135
Solution of P/C: finite circular buffer of
size k
Initialization: S.count:=1;
N.count:=0;
E.count:=k;
Producer:
repeat
produce v;
wait(E);
wait(S);
append(v);
signal(S);
signal(N);
forever
Consumer:
repeat
wait(N);
wait(S);
w:=take();
signal(S);
signal(E);
consume(w);
forever
critical sections
append(v):
b[in]:=v;
in:=(in+1)
mod k;
take():
w:=b[out];
out:=(out+1)
mod k;
return w;