一个理发店N个沙发,一个理发椅
理发师:睡觉,理发,收钱
顾客:有沙发,进入等待,否则离开;理发椅空一顾客离开沙发,唤醒理发师;理完付费离开。
顾客
Repeat
if count>N then
离开店
else
count=count+1
if count=1 then
wait(empty)等椅子
else
wait(sofa)
坐入沙发
wait(empty)等椅子
离开沙发
signal(sofa)
end if
顾客坐上椅子
…(与理发师的关系)
离开椅子
Signal(empty)
Count=count-1
离开店
end if