liveBook · Manning

Livelock

As explained in Grokking Concurrency

A livelock is a concurrency failure in which tasks remain active but repeatedly relinquish and reacquire resources without making progress.

A livelock is a concurrency failure in which tasks remain active but make no progress. They repeatedly acquire and release resources, politely yielding to one another instead of doing useful work. section 9.5

Livelock commonly appears when tasks compete for multiple shared resources:

  • A task acquires one lock, discovers that another is unavailable, releases the first, and retries. section 9.5
  • Competing tasks can repeatedly interfere with one another while the program state never advances. section 9.11
  • Frequent retries can produce excessive context switching and reduce overall performance. section 9.5
  • Ordering lock acquisition hierarchically can prevent this pattern by ensuring that tasks request resources in a consistent sequence. section 9.5

Two callers who keep hanging up

Imagine calling someone who is simultaneously calling you. You both hang up and try again at the same time, repeating the pattern without connecting. The dining-philosophers version behaves similarly: each philosopher grabs one chopstick, notices the other is unavailable, releases the first, and tries again. Neither philosopher eats. section 9.5

How Grokking Concurrency covers it

How deep it goes
Explains the lock cycle through analogy, philosophers, effects, and Python code, but does not provide a detailed detection algorithm.
Examples
Uses a simultaneous-phone-call analogy, dining philosophers, chopsticks, and a Python threading listing.
What it assumes
Assumes basic concurrency and synchronization primitives while clarifying how lock misuse creates nonprogress.
What you can do after
Diagnose repeated lock concessions and reduce livelock by applying hierarchical lock ordering.
How it connects
Contrasts livelock with deadlock and starvation, and connects it to locks, synchronization, scheduling, and context switching.

Also explained in

Compare how 3 books explain livelock →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Concurrency. The section links point to the parts of the book it draws on.