Resource-Allocation Graph
Resource-Allocation Graph
Deadlocks can be precisely described and analyzed using a resource-allocation graph. This graph provides a visual and formal way to represent how threads and resources interact in a system and helps determine whether a deadlock is possible or has occurred.
1. What Is a Resource-Allocation Graph?
A resource-allocation graph is a directed graph defined as:
-
G = (V, E)
-
V: Set of vertices (nodes)
-
E: Set of directed edges
-
2. Types of Nodes
The set of vertices V is divided into two types:
1. Thread Nodes (T)
-
Represent active threads in the system
-
Drawn as circles
2. Resource Nodes (R)
-
Represent resource types
-
Drawn as rectangles
-
Each instance of a resource type is shown as a dot inside the rectangle
3. Types of Edges
Request Edge (Ti → Rj)
-
Indicates that thread Ti has requested resource Rj
-
Thread is waiting for that resource
-
Drawn from a thread node to a resource node
Assignment Edge (Rj → Ti)
-
Indicates that resource Rj has been allocated to thread Ti
-
Drawn from a specific resource instance (dot) to a thread node
4. Graph Evolution During Execution
-
When a thread requests a resource:
-
A request edge is added
-
-
When the resource is granted:
-
The request edge is replaced by an assignment edge
-
-
When the thread releases the resource:
-
The assignment edge is removed
-
5. Interpreting Thread States from the Graph
From a resource-allocation graph, we can directly infer:
-
Which resources a thread holds
-
Which resources a thread is waiting for
-
Whether deadlock is possible
6. Cycles and Deadlock
Case 1: No Cycle in the Graph
✔ No deadlock exists
If the resource-allocation graph has no cycles, then no thread in the system is deadlocked.
Case 2: Cycle Exists in the Graph
A cycle indicates potential deadlock, but the outcome depends on the number of resource instances.
7. Single Instance per Resource Type
If each resource type has exactly one instance:
-
A cycle is necessary and sufficient for deadlock
-
Every thread in the cycle is deadlocked
✔ Cycle ⇔ Deadlock
8. Multiple Instances per Resource Type
If some resource types have multiple instances:
-
A cycle is necessary but not sufficient for deadlock
-
Deadlock may or may not exist
This is because:
-
Another thread may release a resource
-
The cycle can be broken dynamically
9. Example: Deadlock with Multiple Instances
When thread T3 requests resource R2 and no instances are available:
-
A new request edge is added
-
Multiple cycles appear
-
All involved threads are deadlocked
Each thread is waiting for a resource held by another thread in the cycle.
10. Example: Cycle Without Deadlock
A cycle may exist, but:
-
Another thread (e.g., T4) can release a resource
-
That resource breaks the cycle
-
System continues normally
✔ Cycle ≠ Deadlock (always)
11. Key Observations
| Condition | Meaning |
|---|---|
| No cycle | Deadlock impossible |
| Cycle + single instance | Deadlock guaranteed |
| Cycle + multiple instances | Deadlock possible |
12. Why Resource-Allocation Graphs Matter
They help us:
-
Understand how deadlocks form
-
Visually detect deadlock conditions
-
Form the basis for:
-
Deadlock detection algorithms
-
Deadlock avoidance techniques
-
Summary
A resource-allocation graph models threads and resources using directed edges.
If the graph has no cycles, the system is not deadlocked.
If a cycle exists, deadlock may occur—definitely so when each resource type has only one instance.



Comments
Post a Comment