Deadlock, livelock and diagnostics question 140 of 180 mid
What is a livelock, and how does it differ from a deadlock?
- A deadlock that resolves itself
- Correct: Threads keep running and keep responding to each other, but no one makes progress; CPU is busy, unlike a deadlock where everyone is parked
- A thread that never gets CPU time
- A deadlock involving more than two locks
The corridor analogy: two people step aside for each other, repeatedly, in the same direction. Nobody is blocked, everybody is polite, nobody gets through.
In code it usually comes from naive deadlock avoidance: two threads both detect a conflict, both release their locks, both retry immediately, and both collide again. It shows up as high CPU with no throughput, which is the opposite signature to a deadlock, where CPU is at zero and threads are BLOCKED.
The standard fix is randomised exponential backoff, so the retries desynchronise. Ethernet's collision handling is the same idea. Message-driven systems produce a variant where two actors bounce a message back and forth forever.
Quiz yourself on Deadlock, livelock and diagnostics Suggest a correction