3. What is Deadlock ?
A set of blocked processes each holding a resource and waiting to
acquire a resource held by another process in the set.
Example
2 train approaches each other at crossing, both will come to full
stop and neither shall start until other has gone.
8/13/2017
3
4. Deadlock Example
Traffic only in one direction.
Each section of a bridge can be viewed as a resource.
If a deadlock occurs, it can be resolved if one car backs up .
Several cars may have to be backed up if a deadlock occurs. 8/13/2017
4
5. DEADLOCK CHARACTERIZATION
Deadlock can arise if four conditions hold simultaneously.
Mutual exclusion
Hold and wait
No preemption
Circular wait
8/13/2017
5
6. RESOURCE-ALLOCATION GRAPH
Deadlocks can be described in term of directed graph- SYSTEM RESOURCE-
ALLOCATION GRAPH.
Process
Resource Type with 4 instances
Pi requests instance of Rj
Pi is holding an instance of Rj
p
Pi
Rj
Pi
Rj
8/13/2017
6
9. METHODS FOR HANDLINGDEADLOCK
We can deal with DL problem in 3-ways:
Prevention/Avoidance
Detection/Correction
Ignorance
8/13/2017
9
10. DEADLOCK PREVENTION
Restrain the ways request can be made.
Mutual Exclusion – not required for sharable resources;
must hold for non-sharable resources.
Hold and Wait – must guarantee that whenever a process
requests a resource, it does not hold any other resources.
No Preemption –
Circular Wait –
8/13/2017
10
11. DEADLOCK AVOIDANCE
Requires additional information about how resources are to
be used.
The deadlock-avoidance algorithm dynamically examines
the resource-allocation state to ensure that there can never
be a circular-wait condition.
Resource-allocation state is defined by the number of
available and allocated resources, and the maximum
demands of the processes.
8/13/2017
11
14. DEADLOCK AVOIDANCE ALGORITHM
Single instance of a resource type.
Use a resource-allocation graph
Cycles are necessary are sufficient for deadlock
Multiple instances of a resource type.
Use the banker’s algorithm
Cycles are necessary, but not sufficient for deadlock
8/13/2017
14
15. RESOURCE ALLOCATION GRAPHALGORITHM
Claim edge Pi Rj indicates that process Pj may request resource
Rj; represented by a dashed line.
Claim edge converts to request edge when a process requests a
resource.
Request edge converted to an assignment edge when the
resource is allocated to the process.
When a resource is released by a process, assignment edge
reconverts to a claim edge.
Resources must be claimed a priori in the system.
8/13/2017
15
16. BANKER’S ALGORITHM
RAG is not applicable for multiple instance of resource
Bankers’ algorithm - Multiple instances.
Each process claims maximum resource needs a priori.
When a process requests a resource it may have to wait.
When a process gets all of its resources it must return them
in a finite amount of time.
8/13/2017
16