0% found this document useful (0 votes)
6 views44 pages

Deadlock Print 5

Deadlock occurs when there is mutual exclusion between processes, processes hold resources while waiting for more resources, resources cannot be preempted, and there is a circular wait between processes. The four conditions for deadlock are mutual exclusion, hold and wait, no preemption, and circular wait. Deadlock can be detected using algorithms that model resource allocation with matrices.

Uploaded by

fentahunmuluye23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views44 pages

Deadlock Print 5

Deadlock occurs when there is mutual exclusion between processes, processes hold resources while waiting for more resources, resources cannot be preempted, and there is a circular wait between processes. The four conditions for deadlock are mutual exclusion, hold and wait, no preemption, and circular wait. Deadlock can be detected using algorithms that model resource allocation with matrices.

Uploaded by

fentahunmuluye23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Deadlock

Example:

 As shown in figure 4-1, resource T assigned to process D and resource U is assigned to process
C
 Process D is requesting / waiting for resource U AND process C is requesting / waiting for
resource T.
 Processes C and D are in deadlock over resources T and U.
Deadlock
Preemptable and non-preemptable resource
• Resources come in two types: preemptable
and non-preemptable.
A preemptable resource is one that can be
taken away from the process holding it
with no ill effects.
For example, a system with 32 MB of user memory,
one printer, and two 32- MB processes such that each
process wants to print something.
Deadlock
 Process A requests and gets the printer, then starts to
compute the values to print.
 Before it has finished with the computation, it exceeds
its time quantum and is swapped out.
 Process B now runs and tries, unsuccessfully, to
acquire the printer.
 Potentially, we now have a deadlock situation, because
A has the printer and B has the memory, and neither
can proceed without the resource held by the other.
Deadlock
• Fortunately, it is possible to preempt (take away) the
memory from B by swapping it out and swapping A in.
• Now A can run, do its printing, and then release the
printer. No deadlock occurs
Deadlock
 A non-preemptable resource, in contrast, is one that
cannot be taken away from its current owner without
causing the computation to fail.
 If a process has begun to burn a CD-ROM, suddenly
taking the CD recorder away from it and giving it to
another process will result in a garbled CD, CD
recorders are not preemptable at an arbitrary moment.
 In general, deadlocks involve non-preemptable
resources.
Deadlock
List the conditions that lead to deadlock
There are four conditions that must hold for deadlock:
1) Mutual exclusion condition
 Each resource is either currently assigned to exactly
one process or is available.
2) Hold and wait condition
 Process currently holding resources granted earlier can
request more resources
Deadlock
3) No preemption condition
 Previously granted resources cannot be forcibly
taken away from process.
4) Circular wait condition
 There must be a circular chain of 2 or more
processes.
 Each process is waiting for resource that is held
by next member of the chain
Pretend (imagine) that there’s no problem.
 This is the easiest way to deal with problem.
 This algorithm says that stick your head in the sand and pretend
(imagine) that there is no problem at all
Deadlock ignorance. OR
Explain Ostrich Algorithm.
 This strategy suggests to ignore the deadlock because
deadlocks occur rarely, but system crashes due to
hardware failures, compiler errors, and operating
system bugs frequently, then not to pay a large penalty
in performance or convenience to eliminate deadlocks.
This method is reasonable if
Deadlocks occur very rarely
Cost of prevention is high
When system is difficult to recover
Deadlock ignorance. OR
Explain Ostrich Algorithm.
UNIX and Windows take this approach
• Resources (memory, CPU, disk space) are plentiful
• Deadlocks over such resources rarely occur
• Deadlocks typically handled by rebooting
• Trade off between convenience and correctness
Deadlock Detection and Recovery
Detection Algorithms
Deadlock Detection with One Resource of Each Type
Deadlock Detection with Multiple Resources of Each Type
Deadlock Detection with One Resource of Each Type
Deadlock Detection
One Resource
Deadlock Detection (One Resource)
One Resource
Deadlock detection for multiple resource
• When multiple copies of some of the resources
exist, a matrix-based algorithm can be used for
detecting deadlock among n processes.
Deadlock detection for multiple resource
Deadlock detection for multiple resource
Deadlock detection for multiple resource
Deadlock detection for multiple resource
Deadlock detection for multiple resource
Banker’s Algorithm for Deadlock
Avoidance
• Deadlock can be avoided by allocating
resources carefully
• Carefully analyze each resource request to
see if it can be safely granted.
• Need an algorithm that can always avoid
deadlock by making right choice all the
time.

You might also like