monitor ProducerConsumer
condition full, empty;
integer count;
procedure enter;
begin
if count = N then cwait(full);
enter_item;
count := count + 1;
if count = 1 then csignal(empty);
end;
procedure remove;
begin
if count = 0 then cwait(empty);
remove_item;
count := count - 1;
if count = N-1 then csignal(full);
end;
count := 0;
end monitor;
Some problems with monitors:
- potential for deadlocks (trying to
enter a second monitor from within a
monitor
- no control over scheduling (who
enters monitor, who will resume on a signal, ....)