Combining the Condition Variable with Mutual Exclusion
In this form of condition synchronization, the mutex is used to prohibit changes to the program state upon which the synchronization condition depends. A thread subjected to condition synchronization acquires the mutex, tests the condition, and if the condition is found to be false, enters the condition-variable wait. This wait operation temporarily unlocks the mutex so that other threads can access and update the program state.
A thread that is going to change the program state acquires the mutex, updates the state, and calls the condition-variable’s signal operation to wake-up a thread that is waiting. When the waiting thread is awakened, it reacquires the mutex in preparation for a reevaluation of the synchronization condition. If the condition is still found to be false, the thread again enters the wait. If the condition is found to be true, the thread has achieved synchronization and can now release the mutex and proceed.
In the Synchronization package, condition variable synchronization is included in the
RWCondition class. This class combines the mutex and condition-variable interface. An
RWCondition class instance does not possess its own mutex; you must supply a reference to an
RWMutexLock instance when you construct each condition instance. See
The RWCondition Class for more information about using this class.