Professional Documents
Culture Documents
Deadlocks
Resource Allocation Graph
Conditions
for deadlock
Conditions
for deadlock
Conditions
for deadlock
Conditions
for deadlock
Conditions
for deadlock
Handling Deadlocks
Because, P2 is holding
one instance of R1 but
it does not require any
other resource.
Hence, deadlock is
guaranteed here.
Data Structures for the Banker’s Algorithm
4. If Finish [i] == true for all i, then the system is in a safe state. Otherwise, in an unsafe state.
example
• 5 processes -- P0 ….. P4;
• 3 resource types:
A (10 instances), B (5 instances), and C (7 instances)
• Snapshot at time T0:
Allocation Max Available(Remaining)
ABC ABC ABC
P0 0 1 0 753 332
P1 2 0 0 322
P2 3 0 2 902
P3 2 1 1 222
P4 0 0 2 433
Total= 7 2 5
ex
• The content of the matrix Need is defined to be Max – Allocation
The system is in a safe state since the sequence < P1, P3, P4, P2,
P0> satisfies safety criteria
Given the above state -- can request for (3,3,0) by P4 be
granted?
Given the above state -- can request for (0,2,0) by P0 be
granted?
Deadlock Prevention
Deadlock Prevention
Deadlock Prevention
Ex: P1 (requires R1,R2, R3); gets resources R1, R2, R3
P2 (requires R2, R1, R4); cannot get R1 because it is with P1, and cannot get R2, R4 before R1, so
waits.
P3 (requires R3, R2), cannot get R2 because it is with P1, and cannot get R3 before R2 ,so waits.
Deadlock
Detection
• Keep Track of
current allocated
resources
Deadlock
Detection
Deadlock
Detection
4-2=2
Deadlock
Detection
4-2=2
Deadlock
Detection
Deadlock
Detection
Deadlock Recovery
Deadlock Recovery
Deadlock Recovery