FREE C, close to the metal LESSON · C, close to the metal

Make low-level concurrency portable

Atomics, memory order, interfaces, and system evidence

Atomicity alone does not define what another thread may observe.

C atomics provide indivisible operations plus memory-order relationships. A release operation can publish prior writes; an acquire operation that observes it can make those writes visible. Weaker orders support specialized algorithms but demand a precise proof across compiler and hardware reorderings. Most code should prefer mutexes or established concurrent structures unless measured constraints justify this complexity.

A lock-free label is not a correctness proof, progress guarantee, or performance result.

A fast microbenchmark can conceal a broken interface.

False sharing, allocator behavior, contention, NUMA placement, and reclamation can dominate a concurrent structure outside a toy loop. ABI and FFI boundaries add layout, calling, ownership, and error obligations. Benchmark full workloads, state supported platforms, and place simpler fallbacks behind a stable interface when specialized code is not justified.

Optimize the complete boundary under representative contention, not an isolated instruction.
Practise this lesson free →