※ 引述《mqazz1 (無法顯示)》之銘言:
: two processes, A and B, each need three records, 1, 2, and 3, in a batabase.
: if A asks for them in the order 1, 2, 3, and B asks for them in the same order
: deadlock is not possible
: however, if B asks for them in the order 3, 2, 1, then deadlock is possible
: with three resources, there are 3! or six possible combinations each process
: can request the resources
: what fraction of all the combinations is guaranteed to be deadlock free?
A B deadlock free?
------------------------------------------------
1 2 3 1 2 3 V
1 3 2 V
2 1 3 X
2 3 1 X
3 1 2 X
3 2 1 X
所以如果 A要的順序是1 2 3
那麼B就只有1 2 3 或是 1 3 2 這兩種順序可以保證不會有deadlock
因為如果A要了1或是B要了1 那麼另一個process就沒辦法繼續往下要
因此不會產生deadlock
其他狀況就會因為有可能A要了1 B要了2或3而產生deadlock
同樣狀況
如果A的順序是 1 3 2
B就只能是 1 3 2 或 1 2 3這種順序才可確保deadlock free
簡單來說就是把 1 3 2 的 3跟2分別用本來 2跟3取代來討論就可以了
因為那只是record的編號 並不影響結果
所以只要討論最上面那六種情形即可.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.139.82