2、某寺庙,有小、老和尚若干,有一水缸,小和尚提水入缸供老和尚饮水。水缸可容
发布网友
发布时间:2022-04-29 23:16
我来回答
共1个回答
热心网友
时间:2023-10-10 06:11
Var mutex1, mutex2, empty, full, count: semaphore;
mutex1:=1; mutex2:=1;
empty:=10; full:=0; count:=3;
process 小和尚:
begin
repeat
wait(empty);
wait(count);
wait(mutex1);
从井中取水;
signal(mutex1);
wait(mutex2);
送水入水缸;
signal(mutex2);
signal(count);
signal(full);
until false;
end
process 老和尚:
begin
repeat
wait(full);
wait(count);
wait(mutex2);
从缸中取水;
signal(mutex2);
signal(empty);
signal(count);
until false;
end