Deadlock occurs when two or more processes remain permanently blocked while waiting for a resource currently held by another process in the group.
Typical example: Process P1holds resource A and requests B;
process P2 holds resource B and requests A. Neither can
proceed.
This is a blocking condition that the system cannot resolve on its own
without external intervention (such as restarting or forcibly terminating
the processes).
Holt Diagram
The diagram shows two processes and two resources in a circular wait: P1 holds A and requests B, while P2 holds B and requests A. Neither process can proceed because each is waiting for a resource held by the other, resulting in a deadlock.
Let’s look at another practical example of deadlock: the dining philosophers problem.
The dining philosophers problem is a classic example of synchronization between processes that share resources, introduced by Edsger W. Dijkstra in 1965. Five philosophers sit around a table, with a fork between each pair of neighbors. Each philosopher alternates between thinking and eating, but must acquire both forks beside them to eat.
If everyone picks up one fork and waits for their neighbor’s fork, no one can start eating: a deadlock occurs. Even without a system-wide deadlock, an unfair allocation strategy can force a philosopher to wait indefinitely, causing starvation.
The simulator below lets you observe these situations and see how synchronization decisions affect access to the forks.
Deadlock occurs when a set of processes or threads remains permanently blocked because each is waiting for a resource assigned to another member of the same set. For deadlock to occur, four conditions known as the Coffman conditions must hold simultaneously:
Mutual exclusion: at least one resource is non-shareable; it can be used by only one process or thread at a time.
Hold and wait: a process holds at least one resource it has acquired while waiting for other resources assigned to other processes to be released.
No preemption: resources cannot be forcibly taken from their holders; they must be released voluntarily by the process that acquired them.
Circular wait: there is a closed chain of processes (P0, P1, …, Pn) in which P0 waits for a resource held by P1, P1 waits for a resource held by P2, and so on, until Pn waits for a resource held by P0.
In operating systems and concurrent programming, strategies for addressing the problem fall into four main approaches:
Strategy
Basic idea
Advantages and limitations
Prevention (Deadlock Prevention)
Prevents at least one of the four Coffman conditions from occurring (for example, by imposing a total order on resource acquisition to break circular wait, or by requiring all resources in advance).
Guarantees the absence of deadlocks, but reduces resource utilization and may cause starvation or reduce concurrency.
Avoidance (Deadlock Avoidance)
Dynamically evaluates each resource request before granting it, keeping the system in a safe state (using algorithms such as the Banker’s algorithm).
Dynamically avoids unsafe states, but requires advance information about maximum resource needs and has a higher computational cost.
Detection and recovery
Allows deadlocks to occur, detects them through periodic analysis of wait-for or allocation graphs, and intervenes (by terminating processes or reclaiming resources).
Does not impose strict constraints on resource acquisition, but adds monitoring overhead and may result in lost work or inconsistencies that must be repaired.
Ignoring the problem (Ostrich Algorithm)
The system uses no specific deadlock-handling mechanisms and leaves resolution to the application or a system restart.
Very simple and has no runtime overhead; it is a practical choice in many general-purpose operating systems when deadlocks are rare compared with the cost of prevention or detection.
The Banker’s algorithm, developed by Edsger Dijkstra, is a deadlock avoidance algorithm that dynamically decides whether to grant or defer a process’s resource request. Its name comes from the analogy with a bank that never lends all its available cash if doing so could prevent it from meeting the maximum needs declared by its customers. Similarly, the system grants resources only if it remains in a safe state—that is, if there is at least one execution sequence in which all processes can obtain their declared maximum resources, complete their work, and release them. The algorithm requires each process to declare its maximum resource needs in advance and tracks available, allocated, and still-needed resources. If an allocation would lead to an unsafe state, the request is deferred until other resources become available.
Starvation (or indefinite blocking) occurs when a process that is ready to make progress never obtains—or obtains only after an indefinite delay—the resources or CPU time needed to complete its execution, even though there is no deadlock. Unlike deadlock, in which an entire cycle of processes is permanently blocked, during starvation the system continues to make progress on other processes, while one or more processes are systematically bypassed or deprioritized.