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