Using Condition Variables
In addition to mutual exclusion, you can also synchronize threads using condition synchronization.
In condition synchronization, a thread is delayed (blocked) until the program state satisfies some predicate or condition. A key mechanism for implementing condition synchronization is the condition variable.
A condition variable is an efficient mechanism for waiting for and signaling changes in program state. The basic condition variable defines two operations:
*wait—Causes the calling thread to block until another thread calls the signal function.
*signal—Wakes up one waiting thread.
A condition variable also includes a signal-all, or broadcast operation that can be used to awaken all waiting threads, not just one.