Distributed Deadlock: Lectures On Distributed Systems
Distributed Deadlock: Lectures On Distributed Systems
Distributed Deadlock
Paul Krzyzanowski
Introduction
A deadlock is a condition in a system where a process cannot proceed because it needns to obtain a
resource held by another process but it itself is holding a resource that the other process needs. More
formally, four conditions have to be met for a deadlock to occur in
a system:
wants
1. mutual exclusion P1 R1 P2
A resource can be held by at most one process.
holds
2. hold and wait
Processes that already hold resources can wait for R4 R2
another resource.
3. non-preemption
A resource, once granted, cannot be taken away. P4 R3 P3
4. circular wait
Two or more processes are waiting for resources held by Figure 1. Deadlock
one of the other processes.
Resource allocation can be represented by directed graphs:
P1R1 means that resource R1 is allocated to process P1.
P1R1 means that resource R1 is requested by process P1.
Deadlock is present when the graph has cycles. An example is shown in Figure 1.
2. detection: let deadlocks occur, detect them, and then deal with them.
4. avoidance: choose resource allocation carefully so that deadlocks will not occur.
The last of these, deadlock avoidance through resource allocation is difficult and requires the ability
to predict precisely the resources that will be needed and the times that they will be needed. This is
difficult and not practical in real systems. The first of these is trivially simple. We will focus on the
middle two approaches.
In a conventional system, the operating system is the component that is responsible for resource
allocation and is the one to detect deadlocks. Deadlocks are resolved by killing a process. This, of
course, could create unhappiness for the owner of the process. In distributed systems employing a
transaction model things are a bit different. Transactions are designed to withstand being aborted
and, as such, it is perfectly reasonable to abort one or more transactions to break a deadlock.
Hopefully, the transaction can be restarted later without creating another deadlock.
wants
release messages. Each machine will then respond with either a release message or a negative
acknowledgement to acknowledge receipt of the message.