Skip to content

Deadlock and Starvation

An introduction to deadlock and starvation.

Managing synchronization and resource waiting can expose a system to two important issues:

Simplified illustration of cars and an intersectionFour colored cars approach an intersection formed by two roads from different directions.

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 P1 holds 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.

Holt diagram of a deadlockResource A is assigned to P1, which requests B. B is assigned to P2, which requests A. The requests and assignments form a circular wait.assigned torequestsassigned torequestsResource A1 instanceResource B1 instanceProcess P1Process P2

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.

Your answers to this page's quizzes are saved in your browser's local storage and will be remembered between visits.

What characterizes a deadlock?

  • A process waits while all the others have terminated.
  • Multiple processes remain blocked while waiting for resources held by one another.

    Correct: circular wait prevents the processes involved from proceeding and releasing resources.

  • A process runs slowly but continues to receive CPU time.

Which set correctly describes the four Coffman conditions?

  • Priority, parallelism, preemption, and termination.
  • Mutual exclusion, hold and wait, no preemption, and circular wait.

    Correct: all four must occur simultaneously for a deadlock to arise.

  • Mutual exclusion, aging, circular wait, and resource sharing.

Which strategy avoids deadlock by granting a request only if the system remains in a safe state?

  • Detection and recovery.
  • Avoidance.

    Correct: avoidance evaluates requests dynamically and keeps the system in a safe state.

  • Ignoring the problem.

Which situation is an example of starvation?

  • All processes wait for resources in a cycle and none can proceed.
  • A low-priority process keeps waiting while other processes run.

    Correct: the system makes progress, but that process is continually bypassed.

  • A process terminates and releases the resources it was using.

How can aging reduce starvation caused by priority scheduling?

  • By gradually increasing the priority of processes that remain waiting.

    Correct: this allows a process that is continually bypassed to eventually get CPU time.

  • By lowering the priority of processes that have waited the longest.
  • By preventing all processes from using the CPU at the same time.

Quiz progress

0 / 0 questions answered (0%)

0 correct answers