Bounded Buffer Monitor Example
bounded buffer: monitor
begin buffer: array 0..N-1 of portion;
lastpointer: 0..N-1;
count: 0..N;
nonempty, nonfull: condition;
procedure append(x: portion)
begin if count = N then CONDITION.Wait(nonfull);
buffer[lastpointer] := x;
lastpointer:=(lastpointer+1) MOD N;
count:=count+1;
CONDITION.Signal(nonempty);
end;
procedure remove(result x:portion)
begin if count = 0 then CONDITION.Wait(nonempty);
x:=buffer[(lastpointer-count) MOD N];
count:=count-1;
CONDITION.Signal(nonfull.);
end;
count:=0; lastpointer:=0;