生产者消费者扩展 有n+个进程AA···An和B ()AA···An通过同一个缓沖池各自不断地向B发送消息B不断地取消息它必须取走发来的每个消息刚开始时缓沖区为空使用Pv操作实现之 ()若缓沖区个数增至M个试用PV实现正确通讯 这个问题较为简单请读者自行解决这里给出参考答案
The PV code Using Pascal
var fullemptymutex:semaphore; full=; empty=; mutex=; cobegin procedure A_i(i=n) procedure B: begin begin p(empty); P(full); p(mutex); p(mutex); put message to the buffer; Get the message; v(mutex); v(mutex); v(full); v(empty); end end 返回《操作系统之PV金典》 |