Atomic Memory Operations
Atomic memory operations provide the low-level foundation necessary to implement other synchronization primitives. In general, you can replace all atomic operations of a concurrent algorithm with mutexes and channels. Nevertheless, they are interesting and sometimes confusing constructs, and you should know how they work. If you use them carefully, they can become good tools for code optimization without increasing complexity.
In this chapter, we will explore the following topics:
- Memory guarantees of atomic memory operations
- The compare-and-swap operation
- Practical uses of atomics, including counters, heartbeats/progress meters, cancellations, and detecting change