Professional Documents
Culture Documents
Lec # 14-15-16 ch7 PDF
Lec # 14-15-16 ch7 PDF
Chapter Number 7
R1 R2
R3 R4
• Deadlock
– A set of processes is in deadlock if waiting for
resources that can be free by another process in set
using acquisition and release mechanism of OS.
• Physical / Logical resources
– Printer, tape , memory, CPU --- physical
– File, semaphore etc --- logical
P1 P2 P3
• How many cycles are
there?
R4
• Are P1, P2 and P3
R2
deadlocked?
P3
• How many cycles are P1
there?
• Are the processes
deadlocked?
R2
P4
Deadlock
avoidance
1 2
3
Safe State Banker’s RAG
Algorithm Algorithm Algorithm
Resource Request
Safety Algorithm Algorithm
3a 3b
P1 P2 P1 P2
Claim Edge
Assignment Edge
R2 R2
0
Mukhtar Azim Spring 2016 36
7.5.3.1 Safety Algorithm
Allocation (n x m) Max (n x m) Available (m) Need (n x m)
A B C A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2 7 4 3
P1 2 0 0 3 2 2 1 2 2
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1
Finish
Work (m)
P0 P1 P2 P3 P4
3 3 2
False False False False False
Finish
Work (m)
P0 P1 P2 P3 P4
3 3 2
False False False False False
Find an i such that both
2 and
Finish[i]=False
Finish
Work (m)
P0 P1 P2 P3 P4
5 3 2
False True False False False
Find an i such that both
2 and
Finish[i]=False
Finish
Work (m)
P0 P1 P2 P3 P4
7 4 3
False True False True False
Find an i such that both
3 and
Finish[i]=False
Finish
Work (m)
P0 P1 P2 P3 P4
7 5 3
True True False True False
Find an i such that both
4 and
Finish[i]=False
Finish
Work (m)
P0 P1 P2 P3 P4
10 5 5
True True True True False
Find an i such that both
5 and
Finish[i]=False
Finish
Work (m)
P0 P1 P2 P3 P4
10 5 5
True True True True True
Since there is no i such that Finish[i]=False,
• Detect deadlock
• Recover from it