Lecture 6 Deadlocks
Lecture 6 Deadlocks
Deadlocks
• The Deadlock Problem
• System Model
• Deadlock Characterization
• Methods for Handling Deadlocks
• Deadlock Prevention
• Deadlock Avoidance
• Deadlock Detection
• Recovery from Deadlock
Objectives
• To develop a description of
deadlocks, which prevent sets of
concurrent processes from
completing their tasks
• To present a number of different
methods for preventing or
avoiding deadlocks in a computer
system.
The Deadlock Problem
• A set of blocked processes each holding a
resource and waiting to acquire a resource
held by another process in the set.
• Example
– System has 2 disk drives.
– P1 and P2 each hold one disk drive and each
needs another one.
• Example
– semaphores A and B, initialized to 1
P0 P1
wait (A); wait(B)
wait (B); wait(A)
Bridge Crossing Example
• Pi requests instance of Rj
Pi
Rj
• Pi is holding an instance of Rj
Pi
Rj
Example of a Resource Allocation
Graph
Resource Allocation Graph With A Deadlock
Graph With A Cycle But No Deadlock
Basic Facts
• If graph contains no cycles no
deadlock.
Need
ABC
P0 743
P1 122
P2 600
P3 011
P4 431
• The system is in a safe state since the sequence < P1, P3, P4, P2,
P0> satisfies safety criteria.
Example: P1 Request (1,0,2)
• Check that Request Available (that is, (1,0,2) (3,3,2) true.
Allocation Need Available
ABC ABC ABC
P0 0 1 0 743 230
P1 3 0 2 020
P2 3 0 1 600
P3 2 1 1 011
P4 0 0 2 431
• Executing safety algorithm shows that sequence < P1, P3, P4, P0,
P2> satisfies safety requirement.
• Can request for (3,3,0) by P4 be granted?
• Can request for (0,2,0) by P0 be granted?
Deadlock Detection
• Allow system to enter deadlock state
• Detection algorithm
• Recovery scheme
Single Instance of Each Resource
Type
• Maintain wait-for graph
– Nodes are processes.
– Pi Pj if Pi is waiting for Pj.