Initialization: S.count:=1;
                N.count:=0;
                E.count:=k;
append(v):
b[in]:=v;
in:=(in+1)
     mod 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
take():
w:=b[out];
out:=(out+1)
      mod k;
return w;
critical sections