|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Initialization:
|
S.count:=1;
|
|
N.count:=0;
|
|
in:=out:=0;
|
|
|
|
|
|
|
append(v):
|
b[in]:=v;
|
|
in++;
|
|
|
|
|
|
|
|
|
|
|
|
|
Producer:
|
|
repeat
|
|
produce v;
|
wait(S);
|
|
append(v);
|
signal(S);
|
signal(N);
|
forever
|
|
|
|
|
|
|
|
|
Consumer:
|
|
repeat
|
|
wait(N);
|
|
wait(S);
|
|
w:=take();
|
|
signal(S);
|
|
consume(w);
|
forever
|
|
|
|
|
|
|
|
|
|
|
take():
|
|
w:=b[out];
|
out++;
|
|
return
w;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|