正在加载图片...
procedure deposit(item); if(count=k)monitor.wait (notfull); buf[in]=item; in:=(in+1)mod k; count++; monitor.signal (notempty); } procedure fetch:Item_type; if(count=0)monitor.wait (notempty); item=buf[out] in:=(in+1)mod k; count--; monitor.signal(notfull); return(item); } count=0; in=0: out=0; } 进程:producer,consumer; producer(生产者进程): Item_Type item; f while (true) produce(&item); buffer.enter(); buffer.deposit(item); buffer.leave(); consumer(消费者进程): Item_Type item; while (true) buffer.enter(); item=buffer.fetch(); buffer.leave();procedure deposit(item); { if(count=k) monitor.wait(notfull); buf[in]=item; in:=(in+1) mod k; count++; monitor.signal(notempty); } procedure fetch:Item_type; { if(count=0) monitor.wait(notempty); item=buf[out]; in:=(in+1) mod k; count--; monitor.signal(notfull); return(item); } { count=0; in=0; out=0; } 进程:producer,consumer; producer(生产者进程): Item_Type item; { while (true) { produce(&item); buffer.enter(); buffer.deposit(item); buffer.leave(); } } consumer(消费者进程): Item_Type item; { while (true) { buffer.enter(); item=buffer.fetch(); buffer.leave();
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有