Resource Allocation Graph (RAG):
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
a 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
processes in the system and R={R1,R2,...,Rm} the set
consisting of all the resource types in
the system.
A directed edge from process Pi to resource type Rj
is denoted by Pi ->Rj.
It signifies that process Pi requested an instance of
resource type Rj and is currently waiting for that resource.
A directed edge from resource type Rj to process Pi
is denoted by Rj -> Pi.
It signifies that an instance of resource type Rj
has been allocated to process Pi.
A directed edge Pi
->Rj is called a request
edge, a directed edge Rj
-> Pi is called an assignment
edge.
Pictorially we represent each process Pi as a circle and each resource type Rj as a
square.
Since resource type Rj
may have more than one instance we
represent each such instance
as a dot within the square.
A request edge points to only the square Rj where
as an assignment edge must also designate one of the dots in the square.
When process Pi request an instance of resource
type Rj a request edge is inserted into the resource allocation
graph.
When this request can be fulfilled the request edge is
instantaneously transformed to an assignment edge.
When the process no longer needs access to the resource it
releases the resource and as a result the assignment edge is deleted.
The Resource Allocation Graph depicts the following situation:
1.
The sets
P, R and E;
a. P={P1,P2,P3}
b. R={R1,R2,R3,R4}
c. E={P1->R1,P2->R3,R1->P2,
R2->P2,R2->P1,R3->P3}
2. Resource instances:
a. One instance of resource type R1.
b. Two instances of resource type R2.
c. One instance of resource type R3.
d. Three instances of resource type R4.
3.
Process
States:
a. Process P1 is holding an
instance of resource type R2 and is waiting for an instance of
resource type R1.
b. Process P2 is holding an
instance of R1 and R2 and is waiting for an instance of
resource type R3.
c. Process P3 is holding an
instance of R3.
(Resource Allocation Graph)
(Resource Allocation Graph with deadlock)
(Resource Allocation Graph with cycle but no deadlock)
Given the definition of a resource allocation graph it can be
shown that if the graph contains no cycles then no process in the system
is deadlocked. If the graph
does contain a cycle then a deadlock
may exist.
If each resource type has exactly one instance then a cycle implies that a deadlock has occurred.
If the cycle
involves only a set of resource types each of which has only a single instance
then a deadlock has occurred. Each process involved in the cycle is
deadlocked. In this case a cycle in the graph is both a necessary and sufficient condition for the existence of
deadlock.
If each resource type has several instances then a cycle does not necessarily
imply that a deadlock has occurred. In this case a cycle in the graph is a necessary but not a sufficient condition for the existence of
deadlock.
No comments:
Post a Comment