Computer Science 322 Operating Systems
Mount Holyoke College Spring 2008
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:///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: P0 P1 wait(Q); wait(R); wait(R); wait(Q); ... ... signal(R); signal(Q); signal(Q); signal(R); ... ...