Rust Atomics and Locks: Low-Level Concurrency in Practice
Best for: Experienced Rust developers who want to actually understand memory ordering and how synchronization primitives are implemented, not just how to call them.
- ISBN-13: 9781098119447
- Level: advanced
- Published: 2023
Mara Bos leads Rust’s library team, and it shows: this is the most precise,
least hand-wavy treatment of atomics and memory ordering available for
Rust, or arguably for any language. Rather than presenting Mutex and
Arc as opaque building blocks, the book builds a spinlock, a channel, an
Arc, and a full mutex from raw atomic operations, chapter by chapter,
so that by the end “relaxed,” “acquire,” “release,” and “sequentially
consistent” ordering are concrete operational concepts you’ve used to make
something work, not just a table of definitions you’ve memorized.
The chapter connecting the abstract memory-model rules to what real processors (x86, ARM) actually do at the hardware level is the book’s best single chapter and answers questions (“why does this ordering matter if my CPU doesn’t reorder that instruction”) that most concurrency material never addresses. The whole book is also freely readable at the author’s site, which is a rare and welcome move for an O’Reilly title and makes it easy to sample before buying the print edition.
Where it’s weaker: this is a narrow, deep book on one topic, not a general
concurrency guide — there’s no coverage of async/await, futures, or
async runtimes, and it assumes you’re already comfortable with threads,
Send/Sync, and basic lock usage going in. Read Rust for Rustaceans
first if concurrency primitives are still new territory.
Compared to Rust for Rustaceans: Gjengset’s book teaches you to use concurrency primitives idiomatically; this book teaches you to build them correctly from atomics. They’re complementary rather than competing — this is the natural next step after that book’s concurrency chapter.