liveBook · Manning

Livelock

As explained in C++ Concurrency in Action, Second Edition

A livelock is a state in which threads repeatedly change or retry operations in response to one another without making useful progress.

A livelock occurs when threads keep reacting to one another but make no useful progress. Unlike a deadlock, they are still running: they may repeatedly check or retry an operation rather than block. section 7.1.4 section 11.1.1

Two threads retrying

In a lock-free data structure, two threads may each change the structure in a way that forces the other’s operation to restart. Both loop and retry. It resembles two people trying to pass through a narrow gap at once: each backs away, then tries again. Scheduling may eventually let one proceed, but the repeated retries waste performance. section 7.1.4

Livelock can resemble deadlock because tasks stop progressing, but active loops can drive CPU usage high. Random scheduling may eventually resolve some cases, after a delay. Wait-free code cannot livelock because it bounds the steps required for an operation, though such algorithms may be more complex. section 11.1.1 section 7.1.4

How C++ Concurrency in Action, Second Edition covers it

How deep it goes
Defines the retry cycle, contrasts active checking with blocking, and describes symptoms without detailing detection procedures.
Examples
Uses two threads repeatedly invalidating each other’s operations and an analogy of people retrying passage through a narrow gap.
What you can do after
Diagnose possible livelock from stalled progress combined with active thread execution and high CPU usage.
How it connects
Connects livelock with lock-free data structures, wait-free algorithms, deadlock, spin locks, and thread scheduling.

Also explained in

Compare how 3 books explain livelock →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of C++ Concurrency in Action, Second Edition. The section links point to the parts of the book it draws on.