Professional Documents
Culture Documents
Ilyas Butt
Lecture 11
Deadlock Detection
Allow system to enter deadlock state
Detection algorithm
Recovery scheme
Single Instance of Each Resource Type
Maintain a wait-for graph
Nodes are processes
Pi Pj if Pi is waiting for Pj
2
RAG
wait-for Graph
Detection Algorithm
1. Let Work and Finish be vectors of length m and n,
respectively Initialize:
Work = Available;
for i = 1, 2, , n
if Allocationi 0 then
Finish[i] = false;
else
Finish[i] = true;
5
Process
R = { A, B, C }
Allocatio Request
n
A B C
A B C
P0
010
000
A: 7 instances
P1
200
202
B: 2 instances
P2
302
000
P3
211
100
P4
002
002
C: 5 instances
Work
A
Allocatio Request
n
A B C
A B C
Work
A
P0
010
000
P1
200
202
P2
302
000
P3
211
100
P4
002
002
Allocatio Request
n
A B C
A B C
Work
A
P0
010
000
P1
200
202
P2
302
000
P3
211
100
P4
002
002
Allocatio Request
n
A B C
A B C
Work
A
P0
010
000
P1
200
202
P2
302
000
P3
211
100
P4
002
002
10
Allocatio Request
n
A B C
A B C
Work
A
P0
010
000
P1
200
202
P2
302
000
P3
211
100
P4
002
002
11
Proces Request
s
A B C
P0
000
P1
202
P2
001
P3
100
P4
002
13
Allocati Reque
on
st
A B C A B C
010
000
200
202
302
001
211
100
002
002
Work
A B
14
Work
A
0
0
0
1
0
0
15
16
Detection Algorithm
How often should the detection algorithm be invoked?
Every time a request for allocation cannot be granted
immediatelyexpensive but process causing the
deadlock is identified, along with processes involved
in deadlock
Periodically, or based on CPU utilization
Arbitrarilythere may be many cycles in the resource
graph and we would not be able to tell which of the
many deadlocked processes caused the deadlock. 17
19