LearnThatStack Ace your next interview
Concurrency & Multithreading · question
Question 5 of 54

What is a deadlock and what four conditions must all hold?

beginner
← All Concurrency & Multithreading questions
Re-explain
Visual ↓

A deadlock is a standstill where two or more threads each wait for a resource another holds. None can proceed, so all stay stuck forever. The program hangs without crashing.

All four Coffman conditions must hold at once:

  • Mutual exclusion: only one thread can hold a resource.
  • Hold and wait: a thread keeps what it has while waiting for more.
  • No preemption: you cannot forcibly take a resource away.
  • Circular wait: a cycle of threads each waits on the next.

Break any one and deadlock cannot form. The most common fix targets circular wait by making every thread acquire locks in the same order.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Concurrency & Multithreading One question at a time. Answer out loud, get graded, see what you missed.
See it - interactive diagram
Two threads stuck in a circular wait
Thread 1It holds lock A and waits for B.
Lock BThread 2 holds it. No one else can.
Thread 2It holds lock B and waits for A.
Lock AThread 1 holds it. Nobody can move.
circular wait
Thread 1It holds lock A and waits for B.
Lock BThread 2 holds it. No one else can.
Thread 2It holds lock B and waits for A.
Lock AThread 1 holds it. Nobody can move.
back to Thread 1 — circular wait

Each thread holds one lock and waits for the other lock, so nobody can move. If both threads take the locks in the same order, the circle never forms.

© LearnThatStack - diagrams may not be republished without permission.

Other questions have diagrams like this too. Sign in to ask for one where it's missing - it's free.

Create a free account
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

What you can say

  1. A deadlock is a standstill where two or more threads each wait for a resource another one holds, so none of them can ever move.
  2. The program doesn't crash. It just hangs, and those threads stay stuck for good.
  3. It needs four conditions, the Coffman conditions, and all four have to hold at the same time.
  4. Mutual exclusion means only one thread can hold a resource, and hold and wait means a thread keeps what it has while it waits for more.
  5. No preemption means you can't force a resource away from a thread, and circular wait means there's a cycle where each thread waits on the next.
  6. Break any one and deadlock can't form. The usual fix breaks circular wait by taking locks in one fixed order, but every code path has to follow it, and one path that doesn't brings the risk back.

Weak answers to avoid

  • Recites the four names with no meaning Four labels sound memorized. Give each a one-line meaning, and keep hold and wait apart from circular wait, which weak answers often blur.
  • Thinks any one condition causes deadlock It's the reverse. All four must hold at once, which is why breaking a single one is enough to prevent it.
  • Confuses deadlock with a crash or a race A deadlock hangs, with threads stuck waiting. A race gives wrong results that depend on timing. Blurring the two reads as shaky basics.
  • Defines it but never says how to prevent it The interviewer will ask how you stop it. Get there first and name a consistent lock order as the fix for circular wait.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Concurrency & Multithreading cheatsheet.

← Back to all Concurrency & Multithreading questions
Pro · $10/mo

47 of 54 Concurrency & Multithreading answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime