The Rust programming language is extremely well suited for concurrency, and its ecosystem has many libraries that include lots of concurrent data structures, locks, and more. But implementing those structures correctly can be difficult. Even in the most well-used libraries, memory ordering bugs are not uncommon.
In this practical book, Mara Bos, team lead of the Rust library team, helps Rust programmers of all levels gain a clear understanding of low-level concurrency. You’ll learn everything about atomics and memory ordering and how they're combined with basic operating system APIs to build common primitives like mutexes and condition variables. Once you’re done, you’ll have a firm grasp of how Rust’s memory model, the processor, and the role of the operating system all fit together.
With this guide, you’ll learn:
How Rust's type system works exceptionally well for programming concurrency correctly All about mutexes, condition variables, atomics, and memory ordering What happens in practice with atomic operations on Intel and ARM processors How locks are implemented with support from the operating system How to write correct code that includes concurrency, atomics, and locks How to build your own locking and synchronization primitives correctly
This book is short and surprisingly deep. Great combo. Chapter 3 (Memory Ordering) and Chapter 7 (Understanding the Processor) are the gems of the book. This is one of the best introductions of why concurrency is hard from theoretical perspective and how it looks like on a hardware level.
The books is clearly written and very easy to read. I think if you have basic understanding of rust (i.e. finished first half of the rust book) - you are good to read it. The book takes this clean approach of introducing naive way of building locks and then gradually making it more and more realistic and performant, while explaining all complexities but also tools available for a developer to mitigate them
For me, Rust Atomics and Locks strikes the perfect balance between depth and breadth. It is the 'right amount of technical' to keep me engaged.
Mara uses a language that is simple enough for us non-native speakers but not overly simplistic. It is written in a non-overbearing way, so it felt like a smart friend explaining concurrency internals rather than a detached scholarly dissertation.
I highly enjoyed the book and it sets the bar pretty high for both technical books in general and Mara's next endeavors :)
An excellently written, concise book on concurrency in any reasonably low-level language, not just Rust. It is written with all examples being Rust, and from a Rust point of view, so some familiarity with Rust and its ecosystem is helpful, but not vital. As noted by other reviewers, the chapters on Memory Ordering and Processors are the real gems (although there are no bad or wasted chapters here).
Really good book that helped me bring concurrency down to earth. Well explained and full of examples. The only thing I would add is a bit more about intuition, for example, a way to identify how many threads are needed for a solution and under which scenarios threads make sense (notice my lack of experience with threads).
Absolutely loved this book. One of the few tech books I’ve read cover to cover. Mara brilliantly walks the reader through the complex topics of locking and atomics in rust. If dare say this will make my Go a d Kotlin programming better too.