← Lessons

quiz vs the machine

Gold1410

Concurrency

Livelock

When threads keep reacting to each other but make no progress.

4 min read · core · beat Gold to climb

Livelock

A livelock is like a deadlock except the threads are not blocked; they are actively running but still make no progress. Each thread keeps changing state in response to the others, repeating forever.

The everyday analogy is two people in a hallway who both step the same way to let the other pass, then both step back, endlessly. They are busy and polite but stuck.

In code, livelock often appears when threads detect contention and back off, then retry at the same time:

  • Thread A grabs a lock, sees B is waiting, and releases to be fair.
  • Thread B does exactly the same.
  • Both retry in lockstep and the cycle never ends.

Unlike deadlock, the CPU is fully busy, so livelock can be harder to notice. Fixes introduce asymmetry or randomness so the symmetric dance breaks:

  • Add randomized backoff so retries desynchronize.
  • Give threads different priorities.
  • Use a queue so requests are served in a fixed order.

Key idea

Livelock keeps threads busy responding to each other without progress; breaking the symmetry with randomness or priority resolves it.

Check yourself

Answer to earn rating on the learn ladder.

1. How does livelock differ from deadlock?

2. Which fix best breaks a livelock?