Data:
Remaining Need(X) = (max-needs-X) – (has-X)
Remaining Need(Y) = (max-needs-Y) – (has-Y)
Process
|
Remaining Need (X)
|
Remaining Need (Y)
|
A
|
30
|
30
|
B
|
50
|
140
|
C
|
75
|
30
|
D
|
50
|
20
|
Calculation:
Available resource of X = 40
Available resource of Y = 40
Sequence: ACDB
Need of A(30, 30) ≤ available of (40, 40)
A is executed and release the resource held by it
Available of X = 40 + 35 = 75
Available of Y = 40 + 10 = 55
Available of (X, Y) = (75, 55)
Need of C(75, 30) ≤ available of (75, 55)
Also Need of D(X, Y) ≤ available of (X, Y)
Taking C first (as an exercise take D and solve)
C is executed and release the resource held by it
Available of X = 75 + 35 = 110
Available of Y = 55 + 20 = 75
Available of (X, Y) = (110, 75)
Need of D(50, 20) ≤ available of (110, 75) // B won't be satisfied
D is executed and release the resource held by it
Available of X = 110 + 0 = 110
Available of Y = 75 + 70 = 145
Available of (X, Y) = (110, 140)
Need of B(50, 140) ≤ available of (110, 140)
B is executed and release the resource held by it
Available of X = 110 + 50 = 160
Available of Y = 145 + 140 = 285
Available of (X, Y) = (160, 2885)
∴ safe sequence is ACDB
Similarly, safe sequence is ADCB