Course contentsShow
← Computer Science
Lesson 1315 of 2,87230. Process SynchronizationFree lesson

Coffman Conditions for Deadlock

The four necessary conditions that must hold simultaneously for deadlock: mutual exclusion, hold and wait, no preemption, and circular wait.

Coffman Conditions for Deadlock

What You'll Learn

You'll learn the four specific conditions that must all be present at the same time for a deadlock to occur in a system.

The Four Necessary Conditions

In 1971, computer scientist Edward G. Coffman identified exactly what circumstances create deadlock. Think of it like a recipe: if even one ingredient is missing, you can't bake the cake. Similarly, if any one of these four conditions is absent, deadlock cannot happen.

1. Mutual Exclusion

At least one resource must be held in a non-shareable mode. Only one thread or process can use the resource at a time. If another thread wants it, it must wait.

2. Hold and Wait

A thread must be holding at least one resource while waiting to acquire additional resources that are currently held by other threads. It's like holding your parking spot while trying to reserve another one simultaneously.

3. No Preemption

Resources cannot be forcibly taken away from a thread holding them. The thread must voluntarily release the resource. Once you've locked a mutex, the OS can't just yank it away from you.

4. Circular Wait

There must exist a circular chain of two or more threads, where each thread is waiting for a resource held by the next thread in the chain. Thread A waits for Thread B's resource, Thread B waits for Thread C's, and Thread C waits for Thread A's—forming a cycle.

Why This Matters

Understanding these conditions is crucial because deadlock prevention strategies work by ensuring at least one of these four conditions cannot hold. Break any one link, and deadlock becomes impossible.

Key Takeaway: Deadlock requires all four Coffman conditions simultaneously: mutual exclusion, hold and wait, no preemption, and circular wait. Remove any one, and deadlock cannot occur.