[理工] [OS] monitor
看不太懂3個printer給n個process with priority queue的問題
Monitor 定義
type Allocator = Monitor
Var P[0..2] of Boolean //printer state
x: condition
Procedure entry Acquire(i:priority number,pid:printer ID)
begin
if(P[0] && P[1] && P[2]) then x.wait(i);
if(!P[0]) pid = 0;
else if(!P[1]) pid = 1;
else pid = 2;
p[pid] = ture;
end;
Procedure entry Release(pid:printer ID)
begin
p[pid] = false;
x.signal
end;
begin
for i = 0 to 2 do p[pid] = false;
end;
共享變數 PA:Allocator
Pi process
PA.Acquire(i,pid);
using 第pid printer
PA.Release;
看得很不懂
為什麼Release x.signal後,最後那邊要把 p[pid] 都變false
這樣之前在queue裡面的不就可能搶到其它非目前release 出來的 pid 的printer
還有這樣是不是就沒辦同時使用3個printer
因為任何時間點不是只能有一個process呼叫monitor的 procedure嗎
還是說因為開始使用printer了 所以此時可有另一個process再call acquire
問得有點混亂不好意思
感覺這部分都好像有點難懂
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.121.171.238
推
09/20 10:55, , 1F
09/20 10:55, 1F
推
09/20 12:55, , 2F
09/20 12:55, 2F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
理工
1
15