What is a mutex lock primarily used for in programming?

  • ATo encrypt data
  • BTo prevent multiple threads from accessing shared resources simultaneously
  • CTo speed up execution
  • DTo handle recursion
Show answerHide answer

Correct answer B

A mutex (mutual exclusion) lock ensures that only one thread can access a shared resource at a time. It prevents race conditions, where multiple threads modify data simultaneously. Threads must acquire the mutex before using the resource and release it afterward. Mutexes are commonly used in multithreading and concurrent programming. Proper use of mutexes ensure s data consistency and program stability.