Resource-allocation graphs
Build graphs and spot cycles interactively.
Operating Systems: Resource Allocation Graphs
1. What is a Resource Allocation Graph (RAG)?
A Resource Allocation Graph (RAG) is a directed graph used to model system state and identify deadlocks visually. By representing processes, resources, and their directional dependencies, RAGs allow OS designers to inspect whether a set of processes is trapped in mutual waiting.
2. Graph Components: Vertices & Edges
Represent active processes in the system (\(P_1, P_2, P_3, \dots\)). Rendered visually as Circles.
Represent resource types (\(R_1, R_2, R_3, \dots\)). Rendered visually as Rectangles. Individual dots inside represent resource instances.
A directed edge pointing from a Process to a Resource box. Indicates process \(P_i\) is currently waiting for an instance of resource \(R_j\).
A directed edge pointing from an internal instance dot inside Resource \(R_j\) to Process \(P_i\). Indicates an instance of \(R_j\) is currently held by \(P_i\).
3. Graph Analysis Rules for Deadlock Detection
Analyzing deadlocks using Resource Allocation Graphs depends directly on the existence of directed cycles and the number of resource instances:
Rule 1: No Cycle \(\rightarrow\) No Deadlock
If the Resource Allocation Graph contains no cycles, the system is completely safe and free from deadlock. All processes can eventually claim resources, execute, and release them.
Rule 2: Cycle Exists \(\rightarrow\) Deadlock Depends on Instances
- Single Instance per Resource: A cycle is a necessary and sufficient condition for deadlock. Cycle = DEADLOCK.
- Multiple Instances per Resource: A cycle is a necessary condition, but NOT sufficient. A cycle might or might not be a deadlock depending on whether external processes can release instances to break the cycle.
4. Multi-Instance Cycle Case Study
Scenario Configuration:
- Resource \(R_1\): 2 instances available \([\bullet][\bullet]\)
- Resource \(R_2\): 1 instance available \([\bullet]\)
- Process \(P_1\): Holds 1 instance of \(R_1\), requests \(R_2\)
- Process \(P_2\): Holds \(R_2\), requests 1 instance of \(R_1\)
- Process \(P_3\): Requests 1 instance of \(R_1\) (Holds no resources)
Trace Step-by-Step Analysis:
- A directed cycle exists: \(P_1 \rightarrow R_2 \rightarrow P_2 \rightarrow R_1 \rightarrow P_1\).
- However, \(R_1\) has 2 instances! The second instance of \(R_1\) can be allocated to \(P_3\).
- When \(P_3\) completes its execution, it releases its instance of \(R_1\).
- \(P_2\) then acquires that freed \(R_1\) instance, completes its task, and releases \(R_2\).
- Finally, \(P_1\) acquires \(R_2\) and finishes execution.
- Result: NO DEADLOCK despite the presence of a cycle!
5. Interactive Resource Allocation Graph Simulator
Switch between predefined graph topologies to inspect cycle presence, instance allocations, and system deadlock state.