Problem Statement
Explain the difference between a mutex and a semaphore.
Explanation
A mutex (mutual exclusion) is a locking mechanism that allows only one thread or process to access a critical section at a time. A semaphore is a signalling mechanism that can allow multiple threads (if count >1) or one thread (binary semaphore) to access a shared resource. A semaphore also supports operations like wait (P) and signal (V). Using semaphores you can implement various synchronization patterns including producer-consumer, but you must take care of issues like deadlock or priority inversion. Understanding this distinction is common in interviews.
