Posts

Showing posts from June, 2026

The Deadlock Dinner

Image
The Deadlock Dinner — CodePuz Puzzles · Concurrency The Deadlock Dinner Can you spot who'll starve before they ever eat? June 2026  ·  CodePuz  ·  8 min read In the last post we talked about RAII — and how a mutex that never gets unlocked can freeze an entire multithreaded system into silence. But that story assumed the bug was accidental: a forgotten unlock on an early return path. Today's puzzle is about something more insidious. A deadlock that happens even when every programmer did exactly what they were supposed to. Every thread locks a mutex. Every thread eventually unlocks it. The code looks correct. And yet, the system still seizes. To see why, we go to dinner. The Setup Edsger Dijkstra's Dining Philosophers is one of the most famous thought experiments in computer science. Five philosophers sit at a round table. Between each adjacent pair of philosophers lies a single fork. ...

RAlI - The Silent Guardian of Your C++ Code

Image
RAII - The Silent Guardian of Your C++ Code How a destructor saved my multithreaded system late at night It was late at night. A multithreaded simulation platform had just frozen solid, no crash, no exception, no log entry. Just silence. The kind of silence that means every thread is waiting for every other thread, and nothing will ever move again. A deadlock. The engineer staring at the thread dump traced it back to an early-return path buried three call levels deep. Someone had locked a mutex, hit an error condition, returned immediately, and never unlocked. Under light load the path was never triggered. Under the stress of a parallel workload with dozens of threads hammering the same subsystem, it was only a matter of time. The mutex stayed locked. The threads piled up. The system seized. The lock had been acquired manually. It had been forgotten manually. These two facts were never meant to be separated and yet they were, by twelve lines of error-handling code a...