Adobe Scan 27-Nov-2024
Adobe Scan 27-Nov-2024
Deadlocks
3.1 Deadlock
In a
multi-programming environment, several processes may Compete for a finite
set of resources. A process requests resources, if the
are allotted to the process resources are available they
otherwise the process enters the wait state. It may
that waiting processes will never happen
again change state, because other
processes hold the resources they have waiting
deadlock. requested. This situation is called a
A set of process is in a
deadiock state if each process in the set is
event that can be caused by only waiting for an
another process in the set.
Definition : A deadlock is a situation in
resource are effectively preventing each otherwhich two processes sharing the same
from accessing the
in both
processes ceasing to function. resource, resulting
The resources may be l/o
devices (such as printers, tapedrives etc), memory
files, and CPU cycles. space,
[90]
Example 3.1
Process 1 requests resource A and receives it.
Resource k Process2 is
Process1 is
requesting
holding Resource
resource A
Process1
Process2
Process 2 is
Process 1i
requesting holding
resource B
Resource B Resource B
FIGURE 3.1
Deadlock Conditions
3.2 Necessary And Sufficient deadlock
simultaneously for a
four conditionsthat must hold
Coffman (1971) identified
to occur.
Mutual exclusion condition
1. at a time.
cannot be used by more than one process
A resource that (91]
2. Hold and wait condition
Processes already holding resources may request new resource In 3.3.
words, there must exist atleast one process that is holding a
resource alrean
allocated to ittwhile wating for additional resource that are currently
by other processes. being hee
3 No preemption condition
resource can be forcibly removed from a process holding it, 3.3.
can be released only by the explicit action of the process. resourcCs
Circular wait condition
Two or more processes form a circular chain where each process wak
resource that the next process in the chain holds. In other words there
exist a set (P. P.. , P) of waiting processes SUch that P, is
waiting for
resource that is held by P,.P, is waiting for a resOurce held by P, and
so on
finally P is waiting for a resource held by P
3.
3.3/Methods for Handling
Deadlocks
There are four methods for handling
deadlock problem.
1. The Ostrich Approach
Just ignore the deadlock
problem altogether.
2. Deadlock Prevention
Deadiocks can be prevented by ensuring that at
least one of the four conditions
(mentioned in Artical 6.10) fails to hold.
3 Deadiock Avoidance
Deadlock can be avoided by careful
resource scheduling,.
4
Deadlock Detection and Recovery
Detect deadlock and, when it
occurs, take steps to recover.
Let consider last three
us
methods
[92]
3.1 Deadlock Prevention conditions
least one of the four
at
Deadlocks can be prevented by ensuring that
(mentioned in Artical 6.10) fails to hold. these conditions.
occurrence of each of
Let us see
how can we prevent the
Exrclusion Condition
211 Elimination of Mutual Ithe resources sharable.
For
all sharable
This condition can be eliminated by making allow tha
would like to access a read-only file, then
example, f several processes are inherently
non-shareabie.
resources such as. printer
to happen. But some from non-sharable to
sharable.
cannot be changed
Therefore, these resources
cannot fulv eliminated. An effort should be made
Hence mutual exclusion condition
to prevent the mutual exclusion.
take the print out of a file, first request and aCquire the disk
For example, to
and printer.
should released all its resources before it requests for additional
(iü) A process
resources.
4= Tape drive
Now the rule is this : processes can request resOurces whenever they wart to,
all requests must be made in increasing order of numbers, A process may reque
first printer and then a tape drive (order :2. 4). but it may not request first a printe
and then a card reader (order: 2, 1).
This method ensure that circular wait condition do not held in the systerm. Theretore,
we nave Seen that by preventing one of these conditions, we can prevent the
deadlock.
DEADLOCK
SAFE
FIGURE 3.2
Example 3.3
Consider that there are total 11 tape drives and three processes. Maximum
requirement and currently allocated tape drives for each process at time t, is shown
in figure 3.3
Maximum
requirement
shown in
and currently
allocated type drives for each process at firne
is figure 3.4
Process
Allocated Maximum Required
6
11
P 2 4
P2 2 6
FIGURE 3.4
FIGURE 3.8
In this example,
Process P, is waiting for a resource R, held by
a resource held by P,. There P,. P, is watry
is a cycle in the
graph and thus the processes
deadiocked.
Deadlock Recovery
When a detection algorithm deternines that a deadiock exists, the systerm should
now be recovered from this state, There are two options for breaking a deadiock
(ii) Rollback
process to some earlier safe
is rollback the preempted
Other possibility
execution from that point.
state and restart its
[101]