Deadlock Prevention, Avoidance, and Detection
Deadlock Prevention, Avoidance, and Detection
and Detection
Deadlock example
An example
bridge
City A
bridge
river
City B
City A
City B
river
Graph-theoretic models
Wait-for graph.
Resource-allocation graph.
Wait-for graph
P2
P1
P3
P5
P4
P2
r1
P1
P2
r2
P3
Resource allocation graph
Without deadlock
P3
With deadlock
P3
P1
P2
P3
P2
Deadlock conditions
Example: OR condition
P3
P1
P3
P4
P2
P1
P5
No deadlock
P4
P2
P5
Deadlock
Deadlock Prevention
Drawback: over-cautions.
Hold Resource
Young process
20
Wants resource
Young process 20
Dies
Holds resource
Old process 10
Wound-wait
Wants resource
Old process 10
Preempts
Hold resource
Young process 20
Wants resource
Hold resource
Young process 20
Old process 10
Waits
An example
Process id priority
Retry
interval
P1
P2
1.5
P3
2.1
P4
3.3
P5
4.0
Deadlock Avoidance
Four resources ABCD. A has 6 instances, B has 3 instances, C
Has 4 instances and D has 2 instances.
Process
Allocation
Max
ABCD
ABCD
P1
3011
4111
P2
0100
0212
P3
1110
4210
P4
1101
1101
P5
0000
2110
Is the current state safe?
If P5 requests for (1,0,1,0), can this be granted?
Centralized approaches
Distributed approaches
Hierarchical approaches
Centralized approaches
Machine 0
A
Holds
Wants
R
Holds
Machine 1
S
Wants
Holds
Coordinator
Coordinator
R
B
R
T
C
T
Distributed approaches
Chandy-Misra-Haas distributed
deadlock detection algorithm
(0,8,0)
Machine 0
0
Machine 1
2
(0,2,3)
Machine 2
(0,4,6)
3
5
(0,5,7)
6
7
Hierarchical approaches
Controller of C.
Every controller in the path from C to A.
Every controller in the path from C to B.