What is a Deadlock in concurrency?

Updated Feb 20, 2026

Short answer

A deadlock occurs when two or more threads are blocked forever, each waiting for resources held by the other.

Deep explanation

Deadlock happens when concurrent processes compete for limited resources and form a circular dependency. Each process holds a resource and waits for another resource that is held by another process.

Four conditions usually lead to deadlock:

  • Mutual exclusion (resource cannot be shared)
  • Hold and wait (holding one resource while waiting for another)
  • No preemption (resources cannot be forcibly taken)
  • Circular wait (cycle of dependencies exists)

Deadlocks can be prevented or handled using strategies like resource ordering, timeouts, or detection algorithms.

Real-world example

Two threads:

  • Thread A holds Lock 1 and waits for Lock 2
  • Thread B holds Lock 2 and waits for Lock 1

Both wait forever, and the system freezes for those tasks.

Common mistakes

  • - Assuming deadlocks always stop the entire system (they may affect only part of it).
  • - Ignoring lock ordering in design.
  • - Not using timeouts in distributed systems.

Follow-up questions

  • How can deadlocks be prevented?
  • What is deadlock detection vs avoidance?
  • What is lock ordering?

More Concurrency interview questions

View all →