[其它]2进程管理
in=0; out=0; count=0 void put(item); { if count=n then notfull.wait; buffer(in):=nextp; in:=(in+1) mod n; count:=count+1; if (notempty.queue) notempty.signal; } void get(item); { if count=0 then notempty.wait; nextc:=buffer(out); out:=(out+1) mod n; count:=count-1; if (notfull.queue) notfull.signal; } producer: begin repeat produce an item; PC. put(item); until false; end consumer: begin repeat PC. get (item); consume the item; until false; end 生产者和消费
原创力文档

文档评论(0)