An article examining atomics in C explores how simple operations like variable increments can break down into multiple steps at the machine level, leading to race conditions in multithreaded code. The C11 standard introduced <stdatomic.h> with atomic types and operations to ensure indivisible execution, while memory ordering semantics like memory_order_relaxed and seq_cst define precise contracts between threads to prevent subtle concurrency bugs.
An overview of atomic variables in C for multithreaded programming. The article explains how to create threads using <threads.h>, the dangers of data races when multiple threads access shared memory, and how atomic variables from <stdatomic.h> provide safe access with various memory ordering semantics including relaxed, acquire/release, and fully ordered modes.
A technical post explores optimizing spin-locks—locks that keep threads spinning on CPU rather than yielding—through incremental improvements in memory ordering and synchronization. By adjusting atomic memory orderings from sequential consistency to acquire-release semantics, the authors achieve 5.7x faster performance and 5.4x lower energy consumption compared to a naive implementation.