Concurrency in Depth
Down to the futex, up to lock-free rings and memory ordering, and out to async — C++ coroutines on epoll, the Go scheduler, and tokio — and when plain threads still win. The C++ treatment of these topics has been extracted into its own dedicated, runnable book, C++ Concurrency and Parallelism (patterncatalyst.github.io/cpp-concurrency-and-parallelism); the chapters here now point to it.
Shared state and the futex
workq builds a bounded MPMC job queue three ways — std::mutex + condvars, a buffered channel, Mutex + Condvar — and we look under all of them at the one primitive doing the work: the futex, whose uncontended fast path is a userspace CAS with no syscall and whose slow path is FUTEX_WAIT/WAKE, proven by strace scaling from 5,186 to 488,818 calls, then broken on purpose under ThreadSanitizer and go -race while Rust refuses to compile the race at all.
Atomics and lock-free: memory ordering, the SPSC ring, and false sharing
spscring drops the lock entirely: a single-producer/single-consumer ring coordinated by two atomic counters, with acquire/release explained on the real head/tail, why a non-atomic ring tears, the ABA problem SPSC sidesteps, and false sharing measured with perf — a padded line beats an unpadded one by ~34% on this host.
Async runtimes and coroutines
chatterd v4 tells the same broadcast three async ways over the same OS threads: hand-rolled C++20 coroutines suspending on an epoll reactor, Go's G-M-P scheduler and netpoller that needed no rewrite, and tokio's tasks-and-Wakers — with /proc/