You are on page 1of 9

Deadlock detection

using resource
allocation graph
example
Done by SATHYA D
Deadlock Characterization

Deadlock can arise if four conditions hold simultaneously.


▪ Mutual exclusion: only one process at a time can use a resource.
▪ Hold and wait: a process holding at least one resource is waiting to acquire
additional resources held by other processes .
▪ No preemption: a resource can be released only voluntarily by the process
holding it, after that process has completed its task .
▪ Circular wait: there exists a set {P0 , P1 , …, P n } 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 , …, P n–1 is waiting for a resource that is held
by P n , and P n is waiting for a resource that is held by P0 .
Resource-Allocation Graph

A set of vertices V and a set of edges E.


● V is partitioned into two types:
● P = {P1 , P2 , …, P n }, the set consisting of all the processes in the system
● R = {R1 , R2 , …, R m }, the set consisting of all resource types in the system
● request edge – directed edge Pi → Rj
● assignment edge – directed edge Rj → Pi
Resource-Allocation Graph

REPRESENTATION
▪ Process Pi

▪ Resource type with 2 instance


Rj
Pi
▪ Pi requests an instance of Rj Rj

Pi
▪ Pi holding an instance of Rj Rj
Example

Rule:
 
In a Resource Allocation Graph,
•If a cycle is being formed, then may be system is in a
deadlock state.
•If no cycle is being formed, then system is not in a
deadlock state.
Example for single instance Resource

P1R1P2R2 R2
P1R1P2R4P1
P3R3P4R4P1R1P2R4
R1
p1
DEADLOCK
OCCURS p3

p2

R4

p4 R3
Example for multiple instance Resource
R1 p5

p2
p1

P1R2P2R1P1
P2R1P5
R2 P1R2P4R3p3
p4
DEADLOCK
p3 DOESN’T
OCCUR HERE
R3
EXAMPLE
R1 p5

p2
p1

P1R2P2R1P1
P2R1P5
R2 P4R3p3R2P2R1P1R2P4
p4
P4R3p3R2P2R1P5
p3 DEADLOCK
OCCURS
R3
THANK YOU

You might also like