Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
A mutex prevents multiple threads from accessing a shared variable at the same time. A condition variable allows one thread to inform other threads about changes in the state of a shared variable (or other shared resource) and allows the other threads to wait (block) for such notification.
A simple example that doesn’t use condition variables serves to demonstrate why they are useful. Suppose that we have a number of threads that produce some “result units” that are consumed by the main thread, and that we use a mutex-protected variable, avail, to represent the number of produced units awaiting consumption: