作者b76516 (阿聰)
看板Grad-ProbAsk
標題[理工] [作業系統]monitor的製作
時間Tue Aug 25 23:20:24 2009
請問用semaphore製作monitor的程式碼的意義為何?
這樣比較好記
謝謝
程式碼如下
變數宣告:
mutex: Semaphore = 1
next: Semaphore = 0
next_count: Integer = 0
x_sem: Semaphore = 0
x_count: Integer =0
[1] 針對每一個 procedure entry F,改寫如下:
wait(mutex);
………
Body of F ………….
………
if next_count > 0 then signal(next)
else signal(mutex)
[2] 針對 x:condition 變數之製作
[2.1] 製作 x.wait
x_count = x_count + 1;
if next_count > 0 then signal(next);
else signal(mutex);
wait(x-sem);
x_count = x_count -1;
[2.2] 製作 x.signal
if x_count > 0 then
begin
next_count = next_count + 1;
signal(x-sem);
wait(next);
next_count = next_count - 1;
end
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.230.137.154
1F:→ yesa315:可以爬文喔 有人發過類似的文章 我爬過 08/26 00:12
2F:推 pp393952:monitor是一種高階資料結構, 第一行的意義就是... 08/26 00:16
3F:→ pp393952:使用semaphore是『製作monitor程式』的一種方法 08/26 00:16