关于操作系统的习题解答
发布网友
发布时间:2022-06-02 15:51
我来回答
共2个回答
热心网友
时间:2023-11-11 05:41
var count:integer:=0;
mutex,sofa,empty,full:semaphore:=1,N,1,0;
cut,payment,receipt:semaphore:=0,0,0;
begin
parbegin
guset:begin
wait(mutex);
if(count>N)then
begin
signal(mutex)
离开;
end
else
begin
count:=count+1;
if(count>1)then
begin
wait(sofa);
就座;
wait(empty)
起来
signal(sofa);
end
else
wait(empty)
就座
signal(full)
理发;
付费
signal(payment)
wait(receipt)
从理发椅上起来
signal(empty)
wait(mutex)
count=count+1;
signal(mutex)
离开理发店
end
end
barber:
begin
repeat
wait(full)
替顾客理发
wait(payment)
收费
signal(receipt)
until false
end
parend
end
真是多!!!!!
热心网友
时间:2023-11-11 05:41
var count:integer:=0;
mutex,sofa,empty,full:semaphore:=1,N,1,0;
cut,payment,receipt:semaphore:=0,0,0;
begin
parbegin
guset:begin
wait(mutex);
if(count>N)then
begin
signal(mutex)
离开;
end
else
begin
count:=count+1;
if(count>1)then
begin
wait(sofa);
就座;
wait(empty)
起来
signal(sofa);
end
else
wait(empty)
就座
signal(full)
理发;
付费
signal(payment)
wait(receipt)
从理发椅上起来
signal(empty)
wait(mutex)
count=count+1;
signal(mutex)
离开理发店
end
end
barber:
begin
repeat
wait(full)
替顾客理发
wait(payment)
收费
signal(receipt)
until false
end
parend
end