Back to Home

Deadlock Visualizer

Watch two threads lock each other in an eternal embrace of death

💀 What is a Deadlock?

A deadlock occurs when two or more threads are blocked forever, each waiting for the other to release a resource. It's like two people meeting in a narrow hallway — each waits for the other to move first, and nobody goes anywhere!

Four Conditions for Deadlock: Mutual exclusion, hold and wait, no preemption, and circular wait. All four must be present for deadlock to occur.

⚠️ The Dangers

  • • Application hangs completely
  • • No error is thrown - silent failure
  • • Hard to reproduce in testing
  • • Can cascade to system-wide failures

✓ Prevention Strategies

  • • Always acquire locks in same order
  • • Use lock timeouts (tryLock)
  • • Deadlock detection algorithms
  • • Lock-free programming

🎬 What to Watch

Thread A acquires Lock 1 and needs Lock 2. Thread B acquires Lock 2 and needs Lock 1. Neither can proceed — classic circular wait deadlock!

Visualization

Lock 1Lock 2Thread AidleThread Bidle
Thread A holds lock
Thread B holds lock
Waiting for lock

Progress

Step 0 of 7

Event Log

Click "Create Deadlock" to start...

How It Happens

Thread A:

acquire(Lock1) → acquire(Lock2)

Thread B:

acquire(Lock2) → acquire(Lock1)

Opposite order = deadlock risk!

💡 How to Prevent Deadlocks

1. Lock Ordering

Always acquire locks in the same order. If everyone acquires Lock1 before Lock2, no circular wait can occur.

2. Lock Timeout

Use tryLock with a timeout. If you can't get the lock in time, release what you have and retry.

3. Deadlock Detection

Monitor for cycles in the wait-for graph. If detected, kill one thread to break the cycle.