Deadlocks (Ch-6)
Deadlocks (Ch-6)
A process must request a resource before using it and must release after
using it
Formal definition :
A set of processes is deadlocked if each process in the set is waiting for
an event that only another process in the set can cause.
Usually the event is release of a currently held resource.
None of the processes can …
run
release resources
be awakened
Example
System has 2 disk drives.
P1 and P2 each hold one disk drive and each needs another one.
Example
P0 P1
wait (A); wait(B)
wait (B); wait(A)
Bridge Crossing Example
Description:
Created (produced) and destroyed (consumed) by a process
Examples:
Interrupts, signals, messages, and information in I/O buffers
Deadlock:
May occur if a Receive message is blocking
May take a rare combination of events to cause deadlock
Consumable Resource Example
P1 P2
... ...
Receive(P2); Receive(P1);
... ...
Send(P2); Send(P1);
System Model - Reusable Resources
Resource types R1, R2, . . ., Rm
CPU cycles, memory space, I/O devices
Each resource type Ri has Wi instances.
Each process utilizes a resource as follows:
request
use
release
Deadlock Characterization
Hold and wait: a process holding at least one resource is waiting to acquire
additional resources held by other processes.
Circular wait: there exists a set {P0, P1, …, Pn} of waiting processes such
that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource
that is held by P2, …, Pn–1 is waiting for a resource that is held by
Pn, and Pn is waiting for a resource that is held by P0.
Necessary Conditions for Deadlock
1) Mutual exclusion:
One process hold a resource in a non-sharable mode. Other processes
requesting resource must wait for resource to be released.
2) Hold-and-wait:
a process must hold at least one allocated resource while awaiting other
resources (one or more) held by other processes.
Necessary Conditions for Deadlock
3) No preemption:
no resource can be forcibly removed from a process holding it. That is,
resources are voluntarily released by the process holding it.
4) Circular wait
a closed chain of processes exists, such that each process holds at least
one resource needed by the next process in the chain
Modeling Deadlock with Graphs
R = {R1, R2, …, Rm}, the set consisting of all resource types in the
system.
Resource-Allocation Graph
Process
Pi requests instance of Rj
Pi
Rj
Pi is holding an instance of Rj
Pi
Rj
Example of a Resource Allocation Graph
Process P2 is waiting
For the resource R3
Which is held by process
P3.
In addition process P1 is
Waiting for process P2 to
Release resource R1
Graph With A Cycle But No Deadlock
No Preemption –
If a process that is holding some resources requests another
resource that cannot be immediately allocated to it, then all
resources currently being held are released.
Preempted resources are added to the list of resources for which
the process is waiting.
Process will be restarted only when it can regain its old resources,
as well as the new ones that it is requesting.