Deadlocks IIITH
Deadlocks IIITH
Distributed Systems
Deadlocks
• Deadlocks is a fundamental problem in systems.
• A process may request resources in any order,
which may not be known a priori and a process
can request resource while holding others.
• If the sequence of the allocations of resources
to the processes is not controlled, deadlocks
can occur.
• A deadlock is a state where a set of processes
request resources that are held by other
processes in the set.
Deadlocks
• The problem appears in standard systems too.
• An Operating System can work on this
problem at multiple levels:
– Detect deadlocks
– Recover from deadlocks
– Prevent deadlocks
• Various algorithms exist for these problems.
Example- Deadlock
Process A Process B
• Lock A • Lock B
• Lock B • Lock A
• Transfer • Transfer
• Unlock A • Unlock B
• Unlock B • Unlock A
Lets Recollect Deadlocks
Revision
System Model
• A process can be in two states:
• Running or blocked.
• In the running state (also called active
• state), a process has all the needed resources
and is either executing or is ready for
execution.
• In the blocked state, a process is waiting to
acquire some resource.
Does cycle indicate deadlock?
Wait for Graph
• A wait for graph(WFG) is a graph where nodes
are processes and there are edges from node
P1 to node P2 if P1 is blocked and it is waiting
for P2 to release some resource. A system is
deadlocked iff there is a cycle or knot in the
WFG
• What we study: Detection and Resolution
Detection:
Don’t detect a deadlock when there isnt one
(false deadlocks)
No undetected deadlock
Phantom Deadlocks
• Lock A
• …………
• Unlock A
• Lock B
• …………
• Unlock B
26
Centralized Deadlock-Detection Algorithms
Ask every process about its wait for
status and create a global wait for
graph. Will this work?
27
Centralized Deadlock-Detection Algorithms
The Ho-Ramamoorthy Algorithms
The Two-Phase Algorithm
Deadlocks don’t go away unless broken. Collect status twice. Take
only those dependencies which are present in both. Any issues?
https://www.geeksforgeeks.org/deadlock-detection-in-distributed-
systems-2/