Lecture 6 OS
Lecture 6 OS
Lecture 6 OS
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Chapter 7: Deadlocks
System Model
Deadlock Characterization
Methods for Handling Deadlocks
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Recovery from Deadlock
Operating System Concepts – 9th Edition 7.2 Silberschatz, Galvin and Gagne ©2013
Chapter Objectives
Operating System Concepts – 9th Edition 7.3 Silberschatz, Galvin and Gagne ©2013
System Model
System consists of resources
Resource types R1, R2, . . ., Rm
CPU cycles, memory space, I/O devices
Each resource type Ri has Wi instances.
Each process utilizes a resource as follows:
request
use
release
Operating System Concepts – 9th Edition 7.4 Silberschatz, Galvin and Gagne ©2013
Deadlock Characterization
Deadlock can arise if four conditions hold simultaneously.
Mutual exclusion: only one process at a time can use a
resource
Hold and wait: a process holding at least one resource is
waiting to acquire additional resources held by other
processes
No preemption: a resource can be released only voluntarily
by the process holding it, after that process has completed
its task
Circular wait: there exists a set {P0, P1, …, Pn} of waiting
processes such that P0 is waiting for a resource that is held
by P1, P1 is waiting for a resource that is held by P2, …, Pn–1
is waiting for a resource that is held by Pn, and Pn is waiting
for a resource that is held by P0.
Operating System Concepts – 9th Edition 7.5 Silberschatz, Galvin and Gagne ©2013
Methods for Handling Deadlocks
Ensure that the system will never enter a deadlock
state--Deadlock prevention
Allow the system to enter a deadlock state and then
recover--Deadlock avoidence
Ignore the problem and pretend that deadlocks never
occur in the system; used by most operating systems,
including UNIX
Operating System Concepts – 9th Edition 7.6 Silberschatz, Galvin and Gagne ©2013
Deadlock Prevention
Restrain the ways request can be made
Operating System Concepts – 9th Edition 7.7 Silberschatz, Galvin and Gagne ©2013
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 to regain its old resources, as
well as the new ones that it is requesting
Circular Wait – impose a total ordering of all resource types
Operating System Concepts – 9th Edition 7.8 Silberschatz, Galvin and Gagne ©2013
Deadlock Avoidance
Requires that the the operating system have a priori information about
how each process will utilize system resources
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 – 9th Edition 7.9 Silberschatz, Galvin and Gagne ©2013
Basic Facts
Operating System Concepts – 9th Edition 7.10 Silberschatz, Galvin and Gagne ©2013
Avoidance Algorithms
Single instance of a resource type
Use a resource-allocation graph
Operating System Concepts – 9th Edition 7.11 Silberschatz, Galvin and Gagne ©2013
Detection-Algorithm Usage
When, and how often, to invoke depends on:
How often a deadlock is likely to occur?
Operating System Concepts – 9th Edition 7.12 Silberschatz, Galvin and Gagne ©2013
Recovery from Deadlock: Process Termination
Operating System Concepts – 9th Edition 7.13 Silberschatz, Galvin and Gagne ©2013
Summary
If a system does not employ a protocol to ensure that deadlocks will never
occur, then a detection-and-recovery scheme may be employed. A dead
lock detection algorithm must be invoked to determine whether a deadlock
has occurred.
If a deadlock is detected, the system must recover either by terminating
some of the deadlocked processes or by preempting resources from some
of the deadlocked processes.
A dead lock can occur only if four necessary conditions hold simultaneously
in the system: mutual exclusion, hold and wait, no preemption, and circular
wait.
To prevent deadlocks, we can ensure that at least one of the necessary
conditions never holds.
A dead locked state occurs when two or more processes are waiting
indefinitely
Operating System Concepts – 9th Edition 7.14 Silberschatz, Galvin and Gagne ©2013
Summary
For an event that can be caused only by one of the waiting processes.
There are three principal methods for dealing with deadlocks:
1. Use some protocol to prevent or avoid deadlocks, ensuring that the system
will never enter a deadlocked state.
2. Allow the system to enter a deadlocked state, detect it, and then recover.
3. Ignore the problem altogether and pretend that deadlocks never occur in the
system.
Operating System Concepts – 9th Edition 7.15 Silberschatz, Galvin and Gagne ©2013
Practice Exercises
If a system does not employ a protocol to ensure that deadlocks will never
occur, what will be employed?
A dead lock can occur only if four necessary conditions hold simultaneously
in the system, state the conditions.
Operating System Concepts – 9th Edition 7.16 Silberschatz, Galvin and Gagne ©2013
End of Chapter 7
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013