一个系统有n个资源R 0 ,…,R n-1 ,k个进程P 0 ,….P k-1 。每个进程P i的资源请求逻辑的实现如下:
if (i % 2 == 0) {
if (i < n) request Ri
if (i+2 < n) request Ri+2
}
else {
if (i < n) request Rn-i
if (i+2 < n) request Rn-i-2
}
在以下哪种情况下可能出现死锁?
(A) n=40, k=26
(B) n=21, k=12
(C) n=20, k=10
(D) n=41, k=19答案:(乙)
解释:
Option B is answer
No. of resources, n = 21
No. of processes, k = 12
Processes {P0, P1....P11} make the following Resource requests:
{R0, R20, R2, R18, R4, R16, R6, R14, R8, R12, R10, R10}
For example P0 will request R0 (0%2 is = 0 and 0< n=21).
Similarly, P10 will request R10.
P11 will request R10 as n - i = 21 - 11 = 10.
As different processes are requesting the same resource, deadlock
may occur.
这个问题的测验