Computer Science 322
Mount Holyoke College
Topic Notes: Deadlock
The idea of deadlock has come up a few times so far:
A group of processes is deadlocked if each process is waiting for an event that can be caused only
by one of the other waiting processes.
Consider a one-lane tunnel (see http://www.teresco.org/pics/xc-19990722-0810/
disk09/mvc-018f.jpg) or underpass:
•One-lane trafﬁc inside the tunnel
•The lane in the tunnel is a shared resource
•If a deadlock like this one occurs, we must tell one of the cars it has to give up its right to
the resource and rollback
•This may mean more than one car has to back up
•Starvation is possible if we keep allowing cars from one direction to enter
The trafﬁc analogy can become more complex with two-way intersections – gridlock!
We have seen the potential for deadlock when using semaphores:
CS 322 Operating Systems Spring 2008
This is a situation that came up with the original “solution” to the dining philosophers.
We will consider processes that need access to more general resources. These could be any non-
preemptable resources, such as tape drives or CD burners, in addition to things like the semaphores.
Requirements for Deadlock
Four conditions must hold simultaneously for deadlock to arise:
1. Mutual exclusion: only one process at a time can use a resource
2. Hold and wait: a process is holding, but not necessarily using, at least one resource and is
waiting to acquire additional resources held by other processes
3. No preemption: a resource can be released only voluntarily by the process holding it, after
that process has completed its task
4. Circular wait: there exists a circular chain of waiting processes, each of which it waiting for
a resource held by the next process in the chain
If any one of these conditions does not hold, deadlock cannot occur.
Resource Allocation Graphs
We model systems for our study of deadlock using directed graphs.
The vertices of our graph are processes, represented by circles,
and resources, represented by squares, which may have a number of “dots” inside to indicate
multiple equivalent instances of a resource.