The PV code Using Pascal
begin var max_capacity=n barber_chair= cust_ready= finished= leave_b_chair=: semaphore; cobegin process barber begin repeat; p(cust_ready); 理发; until false end process customer begin repeat; p(max_capacity);//是否有空闲椅子 进入店里 p(barber_chair);//是否有空闲的理发椅 坐在理发椅上 v(cust_ready);//唤醒理发师 p(finished);//是否完成理发 离开理发椅 v(leave_b_chair); 离开店 v(max_capacity); until false end coend end 返回《操作系统之PV金典》 [] [] [] |