by raphar · 2y ago · 0 comments
My #1 actually isn't a book at all, but the two "atomic Weapons" talks by Herb Sutter, which are extremely good. https://youtu.be/A8eCGOqgvH4 https://youtu.be/KeLBd2EJLOU
Most of the content is not too specific to Linux, much like this book is not too specific to Rust.
The only places I know where it isn’t applicable are the Linux kernel and Java, because their memory models and concurrency primitives predate and significantly differ from the Rust/C++/C models.
For the Linux memory model, there is Paul McKenney’s free book, “is parallel programming hard, and if so, what can you do about it?” https://cdn.kernel.org/pub/linux/kernel/people/paulmck/perfb...
Make sure you get the second edition, it is updated for C++17.
https://www.amazon.com/C-Concurrency-Action-Anthony-Williams...
For many languages there is nothing resembling this, they tend to not get into the details Mara covers, if you get a mutex and maybe atomic arithmetic then they're done.
If you wondered about C or C++, this book is the same content as for those languages but with Rust's syntax. The discrepancy between Rust's memory model and the memory model adopted in C++ 11 and subsequently C is mostly about a feature that's not available in your C or C++ compiler and (which is why Rust doesn't have it) probably won't ever be.
C++ x.store(r1, std::memory_order_relaxed);
is literally the same thing as
Rust x.store(r1, std::sync::atomic::Ordering::Relaxed);
The biggest syntax difference is that C++ x.store(r1) compiles, and in Rust it doesn't. But, chances are after reading Mara's book you will think it's weird not to specify the Ordering needed and never use this uh, convenience.
Java's happens-before memory model is similar to C++'s.
I'll prob get this book, if only for the memory model chapter.
Where do Rust and C++ lie wrt C# and Java?
* while it tells you how to do lock-free programming but doesn't teach you why, nor whether you should it.
* it has a relatively narrow focus on linearizability, but the truth is memory is neither linearizable nor sequentially consistent. These days it is agreed that Lamport's "happens before" relationship and acquire-release are a better way to reason on multithreaded code.
https://docs.oracle.com/javase%2F8%2Fdocs%2Fapi%2F%2F/java/u...