Chapter 7 Deadlocks
Chapter 7 Deadlocks
Chapter 7 Deadlocks
Operating System Concepts – 8th Edition Silberschatz, Galvin and Gagne ©2009
Chapter 7: Deadlocks
The Deadlock Problem
System Model
Deadlock Characterization
Methods for Handling Deadlocks
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Recovery from Deadlock
Operating System Concepts – 8th Edition 7.2 Silberschatz, Galvin and Gagne ©2009
Chapter Objectives
To develop a description of deadlocks, which prevent sets of
concurrent processes from completing their tasks
Operating System Concepts – 8th Edition 7.3 Silberschatz, Galvin and Gagne ©2009
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)
Operating System Concepts – 8th Edition 7.4 Silberschatz, Galvin and Gagne ©2009
Bridge Crossing Example
Operating System Concepts – 8th Edition 7.5 Silberschatz, Galvin and Gagne ©2009
System Model
Operating System Concepts – 8th Edition 7.6 Silberschatz, Galvin and Gagne ©2009
Methods for Handling Deadlocks
Ignore the problem and pretend that deadlocks never occur in the
system; used by most operating systems, including UNIX
Operating System Concepts – 8th Edition 7.7 Silberschatz, Galvin and Gagne ©2009
Deadlock Prevention
Operating System Concepts – 8th Edition 7.8 Silberschatz, Galvin and Gagne ©2009
Deadlock Prevention (Cont.)
No Preemption –
If a process that is holding some resources requests another
resource that cannot be immediately allocated to it, then all
resources currently being held are released
Preempted resources are added to the list of resources for which
the process is waiting
Process will be restarted only when it can regain its old resources,
as well as the new ones that it is requesting
Operating System Concepts – 8th Edition 7.9 Silberschatz, Galvin and Gagne ©2009
Deadlock Avoidance
Operating System Concepts – 8th Edition 7.10 Silberschatz, Galvin and Gagne ©2009
Safe State
When a process requests an available resource, system must decide
if immediate allocation leaves the system in a safe state
That is:
If Pi resource needs are not immediately available, then Pi can
wait until all Pj have finished
When Pj is finished, Pi can obtain needed resources, execute,
return allocated resources, and terminate
When Pi terminates, Pi +1 can obtain its needed resources, and so
on
Operating System Concepts – 8th Edition 7.11 Silberschatz, Galvin and Gagne ©2009
Basic Facts
Operating System Concepts – 8th Edition 7.12 Silberschatz, Galvin and Gagne ©2009
سؤالك ق د يفتح آفاق ًا جدي دة لم
أو يط رق أبواب ًا مغلق ة لم.. ُتْس َبر
تأمالت_حياة# .. ُتفتح
13
Operating Systems
Operating System Concepts – 8th Edition 7.13 Silberschatz, Galvin and Gagne ©2009