Read Section SG 6.7
x._wait
and x.signal
where x
is a monitor condition variable. Since the monitor
assures mutual exclusion, they are used without a mutex lock.
x
condition;
x.wait
blocks a process.
x.signal
unblocks exactly one process waiting for the condition variable
x
. If none are blocked, signal
has no effect.
x.signal
is called by P and Q is waiting. Only
one process can be in the monitor. What happens:
monitor ProducerConsumer { condition full, empty; int count; void enter(void) { if (count == N) full.wait(); enter_item(); count++; if (count == 1) empty.signal(); } void remove(void) { if (count == 0) empty.wait(); remove_item(); count--; if (count == N-1) full.signal(); } }How the producer and consumer programs use the monitor?
synchronized
is used to indicate that the method is part of a monitor.
Skill: Understand how to use monitors.