Deadlocks
Deadlocks
Process
Pi requests instance of Rj Pi
Rj
Rj
Pi is holding an instance of Rj Pi
Resource Allocation Graph With A Deadlock
Before P3 requested After P3 requested an
an instance of R2 instance of R2
Graph With A Cycle But No
Deadlock
Prevention
Ensurethat the system will never enter
a deadlock state
Avoidance
Ensure that the system will never enter
an unsafe state
Detection
Allow the system to enter a deadlock
state and then recover
Deadlock Prevention
Deadlock Prevention
F(tape drive) = 1
F(disk drive) = 5
F(printer) = 12
Deadlock Avoidance
Deadlock Avoidance
Assignment Request
edge edge
Claim
Claim edge
edge
Unsafe State In Resource-Allocation
Graph
Assignment Request
edge edge
Assignment
Claim edge
edge
Resource-Allocation Graph
Algorithm
3 resource types:
A (10 instances), B (5instances), and C (7
instances)
Snapshot at time T0:
Allocation MaxAvailable
ABC ABCABC
P0 0 1 0 753332
P1 2 0 0 322
P2 3 0 2 902
P3 2 1 1 222
P4 0 0 2 433
Example (Cont.)
Resource-Allocation Graph
Corresponding wait-for graph
Multiple Instances of a Resource
Type
Two Approaches
Process termination
Resource preemption
Recovery from Deadlock: Process
Termination