Ch6 Deadlock
Ch6 Deadlock
Operating System Concepts Essentials – 8th Edition Silberschatz, Galvin and Gagne ©2011
Module 6: Process Synchronization
Needed Resources
Definition
Resource-Allocation Graph
Deadlock Detection
Deadlock Prevention
Deadlock Recovery
Operating System Concepts Essentials – 8th Edition 6.2 Silberschatz, Galvin and Gagne ©2011
Needed Resources
Operating System Concepts Essentials – 8th Edition 6.3 Silberschatz, Galvin and Gagne ©2011
Deadlock
Operating System Concepts Essentials – 8th Edition 6.4 Silberschatz, Galvin and Gagne ©2011
Deadlock definition
Deadlock – A deadlocked state occurs when two or more processes are
waiting indefinitely for an event that can be caused by only one of the
waiting processes.
Example
System has 2 disk drives.
P1 and P2 each hold one disk drive and each needs another one.
Operating System Concepts Essentials – 8th Edition 6.5 Silberschatz, Galvin and Gagne ©2011
Resource-Allocation Graph
A visual way to determine if a deadlock has, or may occur.
Operating System Concepts Essentials – 8th Edition 6.6 Silberschatz, Galvin and Gagne ©2011
Resource-Allocation Graph (Cont.)
Process represented by a circle Pi
Operating System Concepts Essentials – 8th Edition 6.7 Silberschatz, Galvin and Gagne ©2011
Resource-Allocation Graph (Cont.)
Operating System Concepts Essentials – 8th Edition 6.8 Silberschatz, Galvin and Gagne ©2011
Resource-Allocation Graph (Cont.)
Operating System Concepts Essentials – 8th Edition 6.9 Silberschatz, Galvin and Gagne ©2011
Conditions for Resource Deadlock
Operating System Concepts Essentials – 8th Edition 6.11 Silberschatz, Galvin and Gagne ©2011
Conditions for Resource Deadlock
Operating System Concepts Essentials – 8th Edition 6.12 Silberschatz, Galvin and Gagne ©2011
Conditions for Resource Deadlock
Operating System Concepts Essentials – 8th Edition 6.13 Silberschatz, Galvin and Gagne ©2011
Conditions for Resource Deadlock
Operating System Concepts Essentials – 8th Edition 6.14 Silberschatz, Galvin and Gagne ©2011
A Chanced Event
Operating System Concepts Essentials – 8th Edition 6.15 Silberschatz, Galvin and Gagne ©2011
A Chanced Event
Operating System Concepts Essentials – 8th Edition 6.16 Silberschatz, Galvin and Gagne ©2011
Multiple Resources
Operating System Concepts Essentials – 8th Edition 6.17 Silberschatz, Galvin and Gagne ©2011
Example of a Resource Allocation Graph
Operating System Concepts Essentials – 8th Edition 6.18 Silberschatz, Galvin and Gagne ©2011
Graph With A Cycle
If the graph contains no cycles, then there are no deadlock processes.
If there is a cycle, then there may be a deadlock:
a) If resource types have multiple instances, then deadlock MAY exist.
b) If each resource type has 1 instance, then deadlock has occurred.
R3 Assigned to P3
P2 Requests P3
Operating System Concepts Essentials – 8th Edition 6.19 Silberschatz, Galvin and Gagne ©2011
Resource Allocation Graph With A Cycle
Operating System Concepts Essentials – 8th Edition 6.20 Silberschatz, Galvin and Gagne ©2011
Methods for Handling Deadlock
There are three strategies:
Ignore deadlocks and pretend that deadlocks never occur in the system.
Operating System Concepts Essentials – 8th Edition 6.21 Silberschatz, Galvin and Gagne ©2011
Deadlock Detection
Operating System Concepts Essentials – 8th Edition 6.22 Silberschatz, Galvin and Gagne ©2011
Deadlock Avoidance – Bankers Algorithm
Operating System Concepts Essentials – 8th Edition 6.23 Silberschatz, Galvin and Gagne ©2011
Deadlock Avoidance – Bankers Algorithm
Consider a system with five processes [P1, P2, P3, P4, P5] and three resource types
[A, B, C]. Resource type A has 3 instances, Resource type B has 3 instances and
Resource type C has 2 instances. Suppose that at time Ts the following snapshot of the
system has been taken in the following table:
1
Operating System Concepts Essentials – 8th Edition 6.26 Silberschatz, Galvin and Gagne ©2011
Operating System Concepts Essentials – 8th Edition 6.27 Silberschatz, Galvin and Gagne ©2011
Deadlock Avoidance – Bankers Algorithm
Consider a system with five processes [P1, P2, P3, P4, P5] and three resources [A, B,
C]. The following table indicates the maximum requirements and current allocations for
these resources:
2
Operating System Concepts Essentials – 8th Edition 6.28 Silberschatz, Galvin and Gagne ©2011
Operating System Concepts Essentials – 8th Edition 6.29 Silberschatz, Galvin and Gagne ©2011
Deadlock Avoidance – Bankers Algorithm
Consider a system with five processes [P1, P2, P3, P4, P5] and four resource types
[A, B, C, D]. Resource type A has 8 instances, Resource type B has 5, Resource type C
has 9 instances and Resource type D has 8 instances. Suppose that at time Ts the
following snapshot of the system has been taken in the following table:
9
Operating System Concepts Essentials – 8th Edition 6.30 Silberschatz, Galvin and Gagne ©2011
Operating System Concepts Essentials – 8th Edition 6.31 Silberschatz, Galvin and Gagne ©2011
Deadlock Prevention
Operating System Concepts Essentials – 8th Edition 6.32 Silberschatz, Galvin and Gagne ©2011
Deadlock Prevention
Operating System Concepts Essentials – 8th Edition 6.33 Silberschatz, Galvin and Gagne ©2011
Deadlock Recovery
Operating System Concepts Essentials – 8th Edition 6.34 Silberschatz, Galvin and Gagne ©2011
Deadlock Recovery
Operating System Concepts Essentials – 8th Edition 6.35 Silberschatz, Galvin and Gagne ©2011
Deadlock Recovery
Operating System Concepts Essentials – 8th Edition 6.36 Silberschatz, Galvin and Gagne ©2011