如何利用管程来解决生产者—消费者问题。急需!!!!!!!!!!!!

如题所述

  type producer-consumer=monitor

  Var in,out,count:integer;

  buffer:array[0,…,n-1] of item;

  notfull, notempty:condition;

  procedure entry put(item)

  begin

  if count≥n then notfull.wait;

  buffer(in)∶=nextp;

  in∶=(in+1) mod n;

  count∶=count+1;

  if notempty.queue then notempty.signal;

  end

  procedure entry get(item)

  begin

  if count≤0 then notempty.wait;

  nextc∶=buffer(out);

  out∶=(out+1) mod n;

  count∶=count-1;

  if notfull.quene then notfull.signal;

  end

  begin in∶=out∶=0; count∶=0 end
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答