Hello! Welcome to the third lesson in our module on Deadlocks.
In our last session, we established a solid foundation by learning how to model a system's state using a Resource Allocation Graph (RAG). We defined its core components—process and resource vertices, and request and assignment edges. Most importantly, we introduced a critical rule: for resources with only a single instance, the presence of a cycle is a necessary and sufficient condition for a deadlock.
Today, we will put that rule into practice. Our learning outcome is to analyze a Resource Allocation Graph to detect deadlocks for single-instance resource types. We will move beyond simple visual inspection and apply a systematic method to prove the existence of a deadlock. This is a crucial skill, as questions involving RAG analysis are common in the GATE exam.
1. The Definitive Rule for Single-Instance Resources
Let's start by cementing the rule we touched on last time. When every resource type in your system has only one instance (like a single CPU or a single printer), the connection between cycles and deadlocks is absolute.
- If the RAG contains a cycle, the system is in a deadlock.
- If the RAG contains no cycle, the system is not in a deadlock.
Why is this so certain? In a cycle, each process is holding a resource that is requested by the next process in the chain. Since there's only one instance of each resource, there are no "spare" resources that could be allocated to break the wait. Every process in the cycle is stuck indefinitely.
Consider the RAG below:

Visually, we can trace the cycle: . Since these are all single-instance resources, we can confidently declare that the system is deadlocked.
The article from GateVidyalay provides a very clear summary of this rule.
Resource Allocation Graph | Deadlock Detection
The article 'Resource Allocation Graph | Deadlock Detection' from GateVidyalay succinctly states the rules for deadlock detection. We will focus on the first rule.
Read the section titled 'Deadlock Detection' and focus on 'Rule-01'. This rule is the cornerstone of today's lesson.
2. Systematic Deadlock Detection
While identifying a cycle by eye is fine for simple graphs, GATE problems can feature more complex RAGs where cycles might not be immediately obvious. For this, we need a robust, algorithmic approach. This method is sometimes called the resource-reduction method and is similar in logic to the safety algorithm we'll see later.
The process is as follows:
- Tabulate the State: Create tables for the
Allocation(resources held by each process) andRequest(resources needed by each process) based on the RAG. - Calculate Availability: Determine the initial
Availableresources. For single-instance resources, this will be zero if all resources are allocated. - Find a Runnable Process: Search for a process that can run to completion. A process can run if it has no outstanding requests.
- Simulate Execution:
- If you find such a process, assume it completes and releases all its allocated resources. Add these back to the
Availablepool. - Remove this process from consideration and repeat from Step 3.
- If you find such a process, assume it completes and releases all its allocated resources. Add these back to the
- Determine the Outcome:
- If all processes can complete, you will have a safe sequence, and there is no deadlock.
- If you reach a point where no remaining process can run (i.e., all remaining processes have requests that cannot be met), the system is in a deadlock.
The following video provides an excellent walkthrough of this method for both a deadlocked and a non-deadlocked system.
L-4.2: Resource Allocation Graph in Deadlock | Single Instance with example | Operating System
The 'Gate Smashers' video we viewed previously demonstrates this systematic analysis perfectly. Pay close attention to how the 'Allocate', 'Request', and 'Availability' tables are used to determine the system's state.
Watch the segment from 03:14 to 22:46. The first part (until 13:28) analyzes a RAG with a deadlock. The second part analyzes a RAG that is proven to be deadlock-free by finding a safe sequence.
Test your understanding!
Consider the following Resource Allocation Graph from the GateVidyalay article. All resources are single-instance.

Is this system in a deadlock? Use the systematic tabular method to prove your answer.
- What are the
AllocationandRequestmatrices? - What is the initial
Availablevector? - Can you find a process that can run to completion?
Show answer
Let's apply the method.
-
Tabulate State:
- Allocation: holds , holds .
- Request: requests , requests .
-
Initial Availability:
- Both resources are allocated, so
Available= [0, 0].
- Both resources are allocated, so
-
Find Runnable Process:
- Can run? Its request is [0, 1]. This is not less than or equal to
Available[0, 0]. So, no. - Can run? Its request is [1, 0]. This is also not less than or equal to
Available. So, no.
- Can run? Its request is [0, 1]. This is not less than or equal to
Since there are no available resources and both remaining processes have outstanding requests, no process can proceed. Therefore, the system is in a deadlock. This matches the cycle we can see visually.
You can verify this with "Method-02" in "Problem-01" of the Resource Allocation Graph | Deadlock Detection article (resource ID LINK).
3. A Key Insight for GATE
A common type of question tests your understanding of the conditions for deadlock. Consider this scenario, which often appears in GATE questions.
Test your understanding!
In the resource-allocation graph of a system, suppose every edge is an assignment edge. This means no process is currently waiting for any resource (i.e., there are no request edges). Is it possible for this system to be in a deadlock?
Show answer
No, the system cannot be in a deadlock. Here's why:
- From a RAG perspective: A deadlock requires a cycle. A cycle must contain both request and assignment edges (e.g., ). If there are no request edges, no cycle can be formed.
- From a conditions perspective: Deadlock requires four necessary conditions. One of these is Hold and Wait, which states that a process must be holding at least one resource and waiting to acquire additional resources. If there are no request edges, no process is waiting for anything. Therefore, the Hold and Wait condition is not met, and deadlock is impossible.
This was part of a question in GATE CSE 2022. You can see the detailed explanation in the Gate Overflow discussion under option D (resource ID LINK).
Conclusion
In this lesson, you've mastered the technique for analyzing Resource Allocation Graphs for single-instance resources—a high-frequency topic in the GATE exam. You now have two powerful tools: quick visual inspection for cycles and a robust, systematic tabular method for formal proof.
Key Takeaways:
- The Golden Rule: For single-instance resources, a cycle in the RAG is a necessary and sufficient condition for deadlock. No cycle means no deadlock.
- Systematic Analysis: You can prove a deadlock exists by showing that no process can run to completion because all waiting processes have unmeetable requests.
- Proving Safety: You can prove a system is deadlock-free by finding a safe sequence—an order in which processes can complete by acquiring resources as they become available.
- Conditions Link: The absence of request edges in a RAG implies the 'Hold and Wait' condition is not met, making deadlock impossible.
In our next lesson, we will shift our focus from detecting deadlocks to preventing them. We will explore practical strategies for designing systems where deadlocks are structurally impossible by ensuring that at least one of the four necessary conditions can never be met.