# Deadlock

> Two tasks each wait for the other. So neither can ever go on.

**Field:** Software Development  
**Category:** Compilers & Runtimes  
**Also known as:** Deadlocks, Deadly Embrace

## Think of it like

Think of it like two cars meeting on a narrow bridge. Neither will back up, so neither can move.

## Definition

A deadlock is when two tasks each wait for something the other holds. Then none of them can go on. Thread A holds lock 1 and waits for lock 2. Thread B holds lock 2 and waits for lock 1. Neither will ever let go, so the program freezes with no error. The usual fix is to always take locks in the same order everywhere.

## Example

Emma's bank app moves money between two accounts. One thread locks Lucy then Jack, the other locks Jack then Lucy. Both wait forever.

## Why it matters

A deadlock gives no error message. The app just stops, which makes it one of the hardest bugs to spot.

## Common mistake

Assuming a frozen app is just slow. Check whether its threads are all waiting on each other.

## Three principles

- **Wait in a circle.** Each holds what the other needs.
- **Silent freeze.** No error shown.
- **Same order.** Take locks the same way.

## Related terms

- [Mutex (Lock)](https://learn.benibix.com/term/development/mutex)
- [Race Condition](https://learn.benibix.com/term/development/race-condition)
- [Thread](https://learn.benibix.com/term/development/thread)
- [Concurrency](https://learn.benibix.com/term/development/concurrency)

## Told apart from

- [Race Condition vs Deadlock](https://learn.benibix.com/compare/race-condition-vs-deadlock): A race condition and a deadlock are both bugs that come from threads sharing data, but they fail in opposite ways. In a race, two threads touch the same data at once with no lock, and the result comes out wrong. In a deadlock, threads hold locks and wait for each other, so nothing runs at all. A race gives wrong answers; a deadlock gives none.

---

Source: https://learn.benibix.com/term/development/deadlock
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
