CS 3733 Operating Systems
Read Pup 10.1 and 10.3
lock and unlock
cond_wait and cond_signal
wait and go to test.
predicate
is true. M and V are the
mutex lock and the condition variable:
lock(M)
while (!predicate) cond_wait(V,M);
...do work
unlock(M)
v:
lock(M)
cond_signal(V)
unlock(M)
If the implementation (such as in the case of POSIX condition variables) only wakes up one
waiting process (thread), a cond_broadcast operation is also provided.
Experiment with the code.
Add command line arguments nproducers and
nconsumers to the main program. Modify the synchronzation
to allow multiple consumers and multiple producers.
Skill: Understand how to use the condition variable-mutex lock combination to solve synchronization problems .