→ wheels:但是若加入atomic的話請看前一篇B大的解法! 08/01 12:58
※ 引述《mqazz1 (無法顯示)》之銘言:
: suppose we have two processes with indices 0 and 1. Assume that count is a
: shared variable between the two processes with initial value zero. (Suppose
: count is implemented without limit in its range.) Also each process with index
: p has a local variable ticket[p] with initial value zero We have the following
: mutual-exclusion algorithm for the two processes in a distributed system.
: while(ture){
: ticket[p] = count = count+1;
: while(ticket[1-p] != 0 && ticket[1-p] < ticket[p]);
我覺得問題是出在這^^^^^^^^^^^^^^^^^^^^^^^^
如果兩個process都抓到相同的ticket值的話
這一行while loop的判斷中 ticket[1-p] < ticket[p]一定不成立
那麼不論AND任何值都會為FALSE 此while loop的condition一定為false
則沒有人會進busy waiting就都跑到CS裡了
所以應該是不滿足mutual-exclusion才對0.0
: CS
: ticket[p] = 0;
: RS
: }
: 請問這分別滿足mutual exclusion, progress, bounded waiting嗎?
: 97台大電機
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.24.175.65