问题 多项选择题

一个理发店由一个有几张椅子的等候室和一个放有一张理发椅的理发室组成。若没有要理发的顾客,则理发师就去睡觉;若一顾客走进理发店且所有的椅子都被占用了,则该顾客就离开理发店;若理发师正在为人理发,则该顾客就找一张空椅子坐下等待;若两位理发师在睡觉,则顾客就唤醒他。试设计一个协调理发师和顾客的程序。

答案

参考答案:共享数据结构是:
var barber,wait:semaphore;{初始值=0}
entry:semaphore;{初始值=A}
couter:integer; {初始值=0}
关于理发师的代码段:
repeat
p(barber);
"share"
until false;
关于顾客的代码段:
p(entry);
if count=n then exit;
count:=count+A;
if count>A then
begin
v(eatry);
p(wait);
end
else
begin
v(entry);
v(barber);
"share"
p(entry);
count:=count-A;
if count>0 then v(wait);
v(entry);
end

填空题
单项选择题