DELAPARRA
Index
Color
NL
Category: Programming paradigms

Deadlock

Explained by Updated

What is Deadlock?

Deadlock: Two or more threads wait forever for locks the others hold — no thread can proceed. A deadlock happens when two or more threads each hold a lock the other needs, and all of them wait forever. Thread A holds lock 1 and waits for lock 2, while thread B holds lock 2 and waits for lock 1.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Deadlock

How is Deadlock used in practice?

Neither can continue, and nothing breaks the tie by itself. In application code this can freeze a process. In databases, the engine usually detects the deadlock and aborts one of the transactions with an error.

What should you keep in mind with Deadlock?

The classic prevention is consistent ordering. If every part of the code always takes locks in the same order, for example always the account with the lower ID first, a cycle cannot form. Keep locks and transactions short, and avoid waiting on external services while holding a lock, because that stretches the window in which a deadlock can occur.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with D

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.