Rust Atomics and LocksMara Bos
Rust Atomics and Locks
by Mara Bos · first published 2022
26mentions
18recommended by
20HN commenters
2023–2026first – last mentioned
90% recommend10% neutral
Why HN recommends it
Clear, detailed explanation of low-level concurrency, atomics, and memory ordering; useful even for non-Rust programmers, and suits readers who already know basic Rust and want deeper systems-level understanding.
Summarised by Claude from recommending comments
Affiliate links. As an Amazon Associate I earn from qualifying purchases.



…benefit of (IMO) being more accessible by describing borrows in terms of the most common effect: to mutate or not. I don't know which choice would have been the right one, but I am at peace with it. "Rust Atomics and Locks" by Mara Bos has a great discussion of these points toward the beginning of her book, and specifically grounds the choice of which terminology to use in concrete and practical terms, which I really appreciated.
on “Getting Past “Ampersand-Driven Development” in Rust” ↗1. Program = Proof by Samuel Mimram Math foundation of programming. Church–Rosser theorem, Curry–Howard correspondence, intuitionistic logic, theorem proving with dependent types, etc. 2. Rust Atomics and Locks: Low-Level Concurrency in Practice by Mara Bos Great introduction even for non-Rust programmers. 3. Statistical Consequences of Fat Tails by N. Taleb et al. I've just started to read it, but looks…
on “Ask HN: Any interesting books you have read lately?” ↗This is a very approachable, yet detailed, introduction to a difficult topic. I wish I had it when I first got into this. Another good resource for me was Mara Bos' book "Rust Atomics and Locks". It is primarily a Rust book , but I found the concise and reduced to the essentials explanations of memory ordering really helpful.
on “C++ Memory Model: Migrating from x86 to ARM” ↗Rust Atomics and Locks by Mara Bors (https://mara.nl/atomics/) is a very good book and available for free online. It does require knowing Rust at least in a basic level, but it explains things very well.
on “Memory Ordering in CPUs” ↗The foreword by Paul E. McKenney makes a great case to read this book even if you don't care about Rust at all: > Which brings us to another group of potential readers, the Rust skeptics. While I do believe that most Rust skeptics are doing the community a valuable service by pointing out opportunities for improvement, all but the most Rust-savvy of skeptics would benefit from reading this book.
on “Rust Atomics and Locks: Low-Level Concurrency in Practice” ↗Thanks for linking all these references! I’m also new to a lot of these topics but recently read Rust Atomics and Locks which has helped my understanding quite a bit - at least keeping me above water reading all the discussion in this post. The examples are in Rust but the concepts are at the kernel/cpu level and apply beyond the language. I recommend it. https://marabos.nl/atomics/
on “An Introduction to Lockless Algorithms” ↗The best exposition of advanced concurrency I know of is Mara Bos' Rust Atomics and Locks - https://marabos.nl/atomics/ also available as a physical book. Don't let the "Rust" reference put you off, the book is relevant to any low-level programming language. (If you're interested in concurrency in a Linux context as seen from a broader systems point of view, you might like Paul McKeneny's 'Is Pa
on “Atomics and Concurrency” ↗Back then, there weren't as good references for explaining atomic ordering, and the blog post had gotten long enough. Mentioning SeqCst was a bit of a cop out, though both Andrea and I didn't end up using SeqCst past the inital impl anyway. Today I would have just linked to https://marabos.nl/atomics/, Mara does a much better job of explaining atomics than I could have then or now.
on “A lock-free ring-buffer with contiguous reservations (2019)” ↗Back when this post was written, I would have agreed with you. But Mara's book makes a good case for this: https://marabos.nl/atomics/memory-ordering.html#common-misco... More importantly, when reading code, SeqCst basically tells the reader: "this operation depends on the total order of every single SeqCst operation in the program," which is an incredibly far-reaching claim. The same code
on “A lock-free ring-buffer with contiguous reservations (2019)” ↗For a more in-depth understanding, I recommend reading "Rust Atomics and Locks": https://marabos.nl/atomics/ It uses Rust for examples, but it more or less applicable to C/C++ as well.
on “Making Sense of Acquire-Release Semantics” ↗> Not too sure what the basic rules are and I'm not able to find any list of such rules. You may want to consider https://marabos.nl/atomics/ for an approachable overview that's still quite rigorous.
on “The Fastest Mutexes” ↗…- The Rustonomicon: https://doc.rust-lang.org/nightly/nomicon/ - Rust Design Patterns: https://rust-unofficial.github.io/patterns/ - Effective Rust: https://www.lurklurk.org/effective-rust/ - Rust Atomics and Locks: https://marabos.nl/atomics/foreword.html - The Little Book of Rust Macros: https://danielkeep.github.io/tlborm/book/index.html - Burn: Deep Learning Framework: https://burn.dev/burn-book/ - API…
on “Rust: Tools (early access edition)” ↗Several other people have commiserated, so rather than do the same maybe we can help. Are you quite sure you understand the atomic primitives you're working with? Mara's book https://marabos.nl/atomics/ is pretty good, it's written in Rust but like, if you thought you needed a Memory Ordering that doesn't cover you're boned because your tools don't support that order (and probably in an appendix
on “What every systems programmer should know about concurrency (2020) [pdf]” ↗In this order: 1. The Rust Book (Free) - https://doc.rust-lang.org/book/ 2. Rust by Example (Free) - https://doc.rust-lang.org/rust-by-example/ 3. Rust Atomics and Locks - https://marabos.nl/atomics/ 4. Rust in Action - https://www.rustinaction.com/ 5. Rust for Rustaceans - https://rust-for-rustaceans.com/ Also Jon Gjengset's channel is immensely valuable: https://www.youtube.com/c/JonGjengs
on “Effective Rust (2024)” ↗You are right about it not being a beginner friendly book. Hence why I placed it lower in the order of books to study. Yeah Rust atomics and locks is essential if you truly want to understand low-level concurrency. But you might have to also refer to the C++ std::atomics reference [1] to get a complete idea. It took me a while to grasp those concepts.…
on “Effective Rust (2024)” ↗