十三 真經之少林寺問題
問題描述
某寺廟
問題分析
從井中取水並放入水缸是一個連續的動作可以視為一個進程
設水井和水缸為臨界資源
The P
var mutex
mutex
empty:=
full:=
count:=
cobegin
Procedure Fetch_Water Procedure Drink_Water
begin begin
while true while true
p(empty); p(full);
P(count); p(count);
P(mutex
Get Water; Get water and
v(mutex
P(mutex
pure water into the jar; v(empty);
v(mutex
v(count); end
v(full);
end
coend
返回《操作系統之PV金典》
From:http://tw.wingwit.com/Article/program/czxt/201311/24305.html