A CppCon 2025 talk by Ben Saks on implementing a custom C++ atomic class template from scratch, motivated by the Arduino Mega 2560 lacking a C++23 atomic header. The talk covers what makes an operation atomic (non-preemptability and synchronizability), demonstrates a lock-free single-producer single-consumer ring buffer using custom atomic head/tail indices, and explains three implementation strategies: disabling hardware interrupts via RAII wrappers, inline assembly with memory clobbers to establish memory barriers, and compiler intrinsic functions like GCC's __atomic_load_n/__atomic_store_n. Memory ordering concepts (acquire/release semantics) and platform-specific considerations for 8-bit vs multi-core systems are also discussed.

1h 1m watch time

Sort: