In Chapter 4, Sync and Send – the Foundation of Rust Concurrency, and Chapter 5, Locks – Mutex, Condvar, Barriers and RWLock, we discussed the fundamentals of lock-based concurrency in Rust. However, there are some cases where lock-based programming is not suitable, such as when extreme performance is a concern or threads may never block. In such domains, the programmer must rely on the atomic synchronization primitives of modern CPUs.
In this chapter, we'll be discussing the atomic primitives available to the Rust programmer. Programming with atomics is a complex topic and an area of active research. An entire book could be dedicated to the topic of atomic Rust programming. As such, we'll be shifting our tactics slightly for this chapter, focusing on more of a tutorial style than previous chapters where...