4. Objectives
On completion of this class, you would be able to
know:
• Definition Dead Lock
• Necessary conditions for the occurrence of Dead lock
• Resource Allocation Graph
• Resource Allocation Graph with a Deadlock
4
5. Deadlocks
•In a multiprogramming environment, several processes
may compete for a finite number of resources
•A process requests resources, if the resources are not
available at that time, the process enters a wait state
• Some times a waiting process may never again able to
change state, because the resources they have requested
are held by other waiting processes
•This situation is called “Deadlock”
5
6. Deadlock
• A set of process is in a deadlock state,
– when every process in the set is waiting far an event,
– that can be caused only by another process in the set
• The resources can be either Physical resources
– like prints, tape drives, memory space, and CPU cycles
or Logical resources
– like files, semaphores and monitors
6
7. Deadlock
Example:
• Consider a system with one printer and one DVD drive
• Suppose that process Pi is holding the DVD and process
Pj is holding the printer
• If Pi requests the printer and Pj requests the DVD
drive, a deadlock occurs
7
8. Necessary Conditions for Deadlock
1. Mutual exclusion
2. Hold and wait
3. No Preemption
4. Circular wait
8
9. Necessary Conditions for Deadlock
Mutual exclusion
•At least one resource must be held in a non-sharable
mode
•The requesting process must be delayed until the
resource has been released
9
10. Necessary Conditions for Deadlock
Hold and wait
•A process must exist that is holding at least one resource
•The process is waiting to acquire additional resources
which are currently being held by other processes
10
11. Necessary Conditions for Deadlock
No preemption
• Resources cannot be preempted
• A resource can be released only voluntarily by the
process holding it
11
12. Necessary Conditions for Deadlock
Circular wait
• A set{P0,P1,…. ,Pn} of waiting processes must exist
such that
• P0 is waiting for resource held by P1
• P1 is waiting for resource held by P2
• Pn-1 is waiting for resource held by Pn
• Pn is waiting for resource held by P0
12
13. Resource Allocation Graph
• Deadlocks can be described more precisely in terms of a
directed graph called a system resource – allocation graph
• This graph consists of a set of vertices V and set of edges E
• The set of vertices V is partitioned into two different types of
nodes:
P = { P1,P2,----, Pn} – the set consisting of all the
active process in the system
R = { R1,R2,----,Rm} - the set consisting of all
resource types in the system 13
14. Resource Allocation Graph
• Pi Rj – Signifies that process Pi has requested an
instance of resource type Rj and is currently waiting for
that resource – request edge
• Rj Pi - signifies that an instance of resource type Rj has
been allocated to process Pi – assignment edge
• Each process Pi is represented by a circle
• Each resource type Rj is represented by a rectangle
14
15. Resource Allocation Graph
The resource allocation graph depicts the following
situation
The sets P,R,E:
• P={P1,P2,P3}
• R={R1,R2,R3,R4}
• E={P1 R1, P2 R3, R1 P2, R2 P2, R2 P1, R3 P3}
15
16. Resource Instances
• One instance of resource type R1
• Two instances of resource type R2
• One instance of resource type R3
• Three instances of resource type R4
16
17. Process States
• Process P1 is holding an instance of resource R2
and is waiting for R1
• Process P2 is holding an instance of R1 and R2 and is
waiting for R3
• Process P3 is holding an instance of R3
17
20. Resource Allocation
• Suppose P3 requests R2
• At this point two minimal cycles exist in the system :
• P1 R1 P2 R3 P3 R2 P1
• P2 R3 P3 R2 P2
• Process P1, P2 and P3 are Deadlocked
20
22. Resource – Allocation
• There is a cycle P1 R1 P3 P1
• But there is no deadlock
• If a resource-allocation graph does not
have a cycle, then the system is not in
a deadlocked state
• If there is a cycle, then the system may
Fig 2
or may not be in a deadlocked state
22
23. Summary
In this class, you have learnt :
• Deadlock
• The necessary conditions for a deadlock to occur namely
• Mutual exclusion
• Hold and wait
• No preemption
• Circular wait
• Resource allocation graphs
23
24. Frequently Asked Questions
1. Explain the necessary conditions that should
exist in a system for a deadlock to occur
2. Explain about resource-allocation graphs
24
25. Quiz
1. Characteristics of deadlock
a) No Hold and wait
b) Circular wait
c) Preemption
d) All of the above
2. Deadlock occurrence
a)In sharable mode
b)In non-sharable mode
25
27. Quiz
3. A directed edge Pi--Rj is called a -------
a) Request edge
4. Deadlocks can be described in terms of -------
a)Resource - allocation
5. A directed edge Rj --- Pi is called an---
a) Assignment edge
27