A system has n resources R0,…,Rn-1, and k processes P0,…..Pk-1. The implementation of the resource request logic of each process Pi. is as follows:
if (i%2 == 0) {
if (i
A system has n resources R0,…,Rn-1, and k processes P0,…..Pk-1. The implementation of the resource request logic of each process Pi. is as follows: 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; } In which one of the following situations is a deadlock possible? Correct Answer n = 21, k = 12
Concept:
A deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process. This makes a cycle.
Explanation:
When n is even:
Even processes(P0, P2, P4...) Requests the even resources(R0, R2,.....) and odd processes (P1, P3,...) requests odd resources(Rn-i, Rn-i-2,.....)
Then, the system never going to deadlock
When n is odd:
Even processes(P0, P2, P4...) Requests the even resources (R0, R2,.....) and odd processes (P1, P3,...) requests also even resources(Rn-i, Rn-i-2,.....)
Then, the system may fall into deadlock
Option 1: deadlock not possible
Here, n=40 is even
so, the system will never fall into deadlock
Option 2: deadlock possible
Here, n= 21, is odd, k=12
| processes | Requests |
| P0 | R0, R2 |
| P1 | R20, R18 |
| P2 | R2, R4 |
| P3 | R18, R16 |
| P4 | R4, R6 |
| P5 | R16, R14 |
| P6 | R6, R8 |
| P7 | R14, R12 |
| P8 | R8, R10 |
| P9 | R12, R10 |
| P10 | R10, R12 |
| P11 | R10, R8 |
Deadlock is possible here because a cycle is detected here
[ alt="F1 Aniket Ravi 08.07.21 D1" src="//storage.googleapis.com/tb-img/production/21/07/F1_Aniket_Ravi_08.07.21_D1.png" style="width: 315px; height: 138px;">
Option 3: deadlock not possible
Here, n=20 is even
so, the system will never fall into deadlock
Option 4: deadlock not possible
n = 41(odd), k = 19
P18 requests R18 and R20
P17 Requests R24 and R22
so, the system will never fall into deadlock
because k!=21
if k=21 then deadlock possible
P19 requests R22 and R20
P20 Requests R20 and R22