1. Introduction
In the previous section, we studied Mutual Exclusion, the first necessary condition for deadlock. We learned that some resources cannot be shared simultaneously and must be allocated exclusively to one process at a time.
The second necessary condition for deadlock is:
Hold and Wait
This condition plays a critical role in deadlock formation because it allows processes to create dependency chains while retaining ownership of resources.
In most real-world systems, processes do not request all required resources at once. Instead, they acquire resources gradually as execution progresses. While this approach improves resource utilization and system efficiency, it also creates the possibility of deadlock.
Understanding Hold and Wait is essential because it acts as the bridge between simple resource allocation and the formation of circular waiting structures that eventually lead to deadlock.
2. Definition of Hold and Wait
A process is said to satisfy the Hold and Wait condition when:
A process holding at least one resource is waiting to acquire one or more additional resources currently held by other processes.
The key idea is that the process:
Already owns some resource(s)
Continues to hold those resources
Simultaneously requests additional resources
Waits without releasing the resources it already possesses
Formally:
Process Holds Resource(s)
+
Requests Additional Resource(s)
This creates a situation where resources become locked inside waiting processes.
3. Understanding the Core Idea
Consider the following situation:
P1 Holds Resource A
while simultaneously:
P1 Waiting For Resource B
Similarly:
P2 Holds Resource B
and:
P2 Waiting For Resource C
In this scenario:
P1 cannot continue until B becomes available
P2 cannot continue until C becomes available
However:
A Remains Occupied By P1
B Remains Occupied By P2
even while they are waiting.
This behavior creates dependency chains among processes.
4. Why Hold and Wait Happens
In practical systems, processes usually acquire resources incrementally rather than requesting everything at startup.
For example, consider a compiler.
The compiler may require:
Memory
first, then later:
Input File Access
and finally:
Printer Access
The process requests resources only when they become necessary.
This approach offers several advantages:
Efficient Resource Utilization
Resources are allocated only when required.
Reduced Resource Wastage
Unused resources remain available for other processes.
Better Throughput
More processes can execute concurrently.
However, the same flexibility introduces the possibility of:
Deadlock Risk
because processes may end up waiting while still holding resources.
5. Step-by-Step Deadlock Scenario
Consider two resources:
Printer
Scanner
and two processes:
P1
P2
Step 1 – P1 Acquires Printer
P1 → Printer
Current allocation:
Printer Occupied
Scanner Free
Step 2 – P2 Acquires Scanner
P2 → Scanner
Current allocation:
Printer Occupied
Scanner Occupied
Step 3 – P1 Requests Scanner
P1 now requires Scanner.
However:
Scanner Held By P2
Therefore:
P1 Waiting For Scanner
while still holding:
Printer
Step 4 – P2 Requests Printer
P2 now requires Printer.
However:
Printer Held By P1
Therefore:
P2 Waiting For Printer
while still holding:
Scanner
Current state:
P1 Holds Printer
P1 Waiting For Scanner
P2 Holds Scanner
P2 Waiting For Printer
This is a classic Hold and Wait situation.
6. Visualization of Hold and Wait
The dependency can be represented as:
P1
↓
Holds Printer
↓
Waiting For Scanner
and
P2
↓
Holds Scanner
↓
Waiting For Printer
Both processes:
Hold Resources
while simultaneously:
Waiting For Additional Resources
This is precisely the Hold and Wait condition.
7. Dependency Chains
One of the most important consequences of Hold and Wait is the creation of dependency chains.
Consider:
P1 Holds A → Waiting For B
P2 Holds B → Waiting For C
P3 Holds C → Waiting For D
P4 Holds D → Waiting For E
This forms a dependency chain:
P1 → P2 → P3 → P4
Each process depends on another process to release a resource.
As the chain becomes longer:
Blocking increases
Waiting time increases
Resource utilization decreases
Deadlock risk grows
If the chain eventually loops back to the beginning:
P4 Waiting For A
a circular dependency forms and deadlock becomes possible.
8. Why Hold and Wait Is Dangerous
The primary danger is that processes continue occupying resources while waiting.
Resources become trapped inside blocked processes.
This creates several problems.
8.1 Resource Blocking
Resources remain unavailable to other processes.
Example:
Printer Held By Waiting Process
Even though the process is not making progress.
8.2 Reduced System Utilization
Resources become locked inside blocked processes.
Resources Allocated
But Not Productively Used
This lowers efficiency.
8.3 Increased Waiting Time
Other processes may also require those resources.
Consequently:
Blocking Spreads Through System
creating larger waiting chains.
8.4 Possibility of Circular Dependency
Dependency chains may eventually form cycles.
Example:
P1 Waiting For P2
P2 Waiting For P3
P3 Waiting For P1
This directly leads to deadlock.
9. Operating System Perspective
From the operating system’s viewpoint, every process maintains two kinds of information:
Allocated Resources
Resources currently owned.
Allocated
Requested Resources
Resources currently being requested.
Requested
The OS tracks this information using:
Resource Allocation Tables
Resource Allocation Graphs (RAG)
Wait-For Graphs (WFG)
These structures help the operating system:
Track Dependencies
Detect Cycles
Identify Deadlocks
10. Why Systems Still Allow Hold and Wait
A natural question arises:
If Hold and Wait can cause deadlock, why do operating systems allow it?
The answer is efficiency.
Suppose every process had to request all resources before starting.
Example:
Memory
Printer
Scanner
Files
would all be allocated immediately.
Many of these resources might remain unused for long periods.
This would lead to:
Poor Resource Utilization
Resources sit idle while reserved.
Reduced Concurrency
Other processes cannot access those resources.
Lower Throughput
Fewer processes execute simultaneously.
Therefore:
Efficiency Requires Incremental Allocation
which naturally permits Hold and Wait.
11. Deadlock Prevention Strategy
One common way to eliminate Hold and Wait is:
Request All Resources at Once
Before execution begins, a process must request:
Every Resource It May Need
Execution begins only after all resources are granted.
Example:
Request:
Memory + Printer + Scanner
Receive All
Start Execution
Because the process never requests additional resources later:
Hold and Wait Eliminated
Why It Works
The process never enters a state where it:
Holds Resource
+
Requests Another Resource
Therefore the Hold and Wait condition cannot occur.
12. Problems with This Prevention Method
Although deadlock risk decreases, new inefficiencies appear.
12.1 Poor Resource Utilization
Resources may remain allocated long before they are needed.
Example:
Printer Reserved
Not Used Yet
12.2 Reduced Concurrency
Processes must wait longer before execution starts.
Start Delayed
until all resources become available.
12.3 Lower Throughput
Fewer processes execute simultaneously.
System Productivity Decreases
13. Alternative Prevention Method
Another approach requires:
A process must release all currently held resources before requesting new resources.
Example:
Instead of:
Hold A
Request B
the process must:
Release A
Request B
Acquire A Again If Needed
This breaks Hold and Wait because the process never waits while holding resources.
Benefits
Hold and Wait Removed
Deadlock possibility decreases.
Drawbacks
However:
Additional Overhead
Resources must be released and reacquired repeatedly.
Increased Execution Time
Extra allocation operations occur.
Performance Loss
System efficiency may decrease.
More Resource Management
Less Useful Work
14. Key Insight
The Hold and Wait condition is the mechanism that allows dependency chains to form.
Without Hold and Wait:
Processes Cannot Create Resource Dependencies
and deadlock becomes impossible.
However, eliminating Hold and Wait completely often leads to:
Poor resource utilization
Lower throughput
Reduced concurrency
Therefore, most operating systems tolerate Hold and Wait and instead rely on deadlock avoidance, detection, and recovery techniques.