What is a Resource Allocation Graph?
A Resource Allocation Graph (RAG) is a directed graph used to represent the relationship between processes and resources in a system.
-
Processes: Represented as circles (e.g., P1, P2).
-
Resources: Represented as squares (e.g., R1, R2).
-
Edges:
When Does Deadlock Occur?
If the graph has a cycle, a deadlock may exist:
Example: No Deadlock
Scenario:
Conditions:
-
P1 is holding R1
-
P2 is holding R2
-
P1 is requesting R2
Graph:
P1 → R2
R1 → P1
R2 → P2
Visualization:
P1 P2
↓ ↓
R2 R1
↑ ↑
←
Example: Deadlock Exists
Scenario:
Conditions:
Graph:
P1 → R2
R1 → P1
P2 → R1
R2 → P2
Visualization:
P1 → R2 → P2 → R1 → P1
Why Use RAG?
-
It provides a clear, visual representation of process-resource relationships.
-
Helps detect potential or actual deadlocks.
-
Useful in systems with single-instance resources.
RAG in Dynamic Systems