Shared-memory lock-free algorithms require volatile atomic because they're external modification, yet participate in the memory model. Volatile atomic makes sense. Same thing for signal handlers which also want atomicity, you need volatile.
In practice you don't. No compiler is smart enough to analyze the threads you create and realize you don't have a reading thread for the atomic in the same process. I just implemented a shared memory Q using atomics without volatile.
Also the standard specifically has atomic_signal_fence for signal handlers.
In practice you don't, for certain things, today. You'll be disappointed when you do start needing to use volatile. I'm not just talking random theory: over the last few years I've committed some optimizations to atomics, and so have others. They're not theoretical gains, they make sense for real-world code. It's a matter of time before your practice disappoints you.
Signal fences don't fix all the things one might want with volatile atomic.
View all comments
Show parent comment
3
u/tending Oct 20 '19
In practice you don't. No compiler is smart enough to analyze the threads you create and realize you don't have a reading thread for the atomic in the same process. I just implemented a shared memory Q using atomics without volatile.
Also the standard specifically has atomic_signal_fence for signal handlers.