What Volatile Means (and Doesn’t Mean) in C++ Programming
Talkat CppCon 2024 · on Monday, 2024-09-16· at 11:00· Cottonwood 2/3, 6700 North Gaylord Rockies Boulevard·
summary
Explains that volatile protects accesses to memory-mapped UART registers (status bit and transmit buffer) by preventing the compiler from eliding or reordering those accesses, but it does not make accesses atomic nor serve as a general threading primitive. Demonstrates a real UART busy‑wait that fails without volatile, shows workaround of non‑inline read/write wrappers plus use of -O0 or pragmas, cites a 2008 paper testing 13 compilers that found miscompilations, and recommends noinline wrappers and memory barriers.
AI-written summary · about
chapters (20)
- 0:00Intro
- 0:36What is Volatile
- 3:24Device Registers
- 7:14Side Effects
- 11:10What Can We Do
- 14:19Declaration Specifiers
- 17:51East Volatile Style
- 20:29Volatile Protections
- 22:35Volatile Dis
- 28:49Volatile Compiler Bugs
- 31:31How to Disable Optimizations
- 35:12Compiler Versions
- 37:35ID and Reger Workaround
- 39:21Inline vs NonInline
- 41:07Serial Port Code
- 42:16Template Versions
- 44:05Takeaways
- 46:14Questions
- 47:43Memory Barriers
- 49:35Deprecation
related talks
47mSecure Coding in C and C++ - Volatility Ahead
33mUndefined Behavior in C++: What Every Programmer Should Know and Fear
01h 02mLock-free programming for real-time systems
55mMemory Model: Get your shared data under control
01h 02mModern C++ Safety and Security At 20
01h 27mDangerous Optimizations! in C++ - Part Deux
34mGetting on the Same (Virtual Memory) Page: A Roundtable on Data-only Attack Mitigations
01h 04mThe C++ Memory Model
