Deadlock in operating systems, undefined for Operating System. Hemwati Nandan Bahuguna Garhwal University

Operating System

Description: Deadlock in operating syatem
Showing pages  1  -  4  of  7
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
disk09/mvc-018f.jpg) or underpass:
One-lane traffic 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 traffic analogy can become more complex with two-way intersections – gridlock!
We have seen the potential for deadlock when using semaphores:
wait(Q); wait(R);
wait(R); wait(Q);
... ...
signal(R); signal(Q);
signal(Q); signal(R);
... ...
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.
CS 322 Operating Systems Spring 2008
Edges from a process to a resource indicate a request by that process for an instance of that re-
Edges from a resource to a process indicate that the resource has been granted to that process.
An example of a resource allocation graph:
There are no cycles in this graph, so we are sure that there is no deadlock. There are two unfulfilled
requests, P1s request for R1, and P2s request for R3, but we are sure things can continue. Since
P3isn’t waiting for anything, it will eventually release R3.P2can then do its thing, allowing it to
release R1, which allows P1to do its thing. But what if P3requests an instance of R2?
CS 322 Operating Systems Spring 2008
Deadlock! P3cannot continue until it acquires an R2. But we know that P2can’t continue until it
gets an R3, which isn’t going to happen until P3can go. But P1is waiting for an R1, which isn’t
available until P2can go... We have a problem. No process can continue.
However, a cycle alone is not enough to guarantee deadlock:
Here, there is a cycle, but P2and P4are not waiting for anything. That means that eventually they
will free their resources, and the other processes can get what they need.
If there is a single instance of each resource, a cycle in the resource allocation graph means we
have deadlock. When there are multiple instances, it only means there is a possibility of deadlock.
Dealing With Deadlocks
The preview of this document ends here! Please or to read the full document or to download it.
Document information
Uploaded by: mohitsaini111
Views: 2340
Downloads : 6
University: Hemwati Nandan Bahuguna Garhwal University
Upload date: 17/03/2012
Embed this document:
Docsity is not optimized for the browser you're using. In order to have a better experience please switch to Google Chrome, Firefox, Internet Explorer 9+ or Safari! Download Google Chrome