看板 Grad-ProbAsk 關於我們 聯絡資訊
請問用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
yesa315:可以爬文喔 有人發過類似的文章 我爬過 08/26 00:12
pp393952:monitor是一種高階資料結構, 第一行的意義就是... 08/26 00:16
pp393952:使用semaphore是『製作monitor程式』的一種方法 08/26 00:16