In this example, does correctness require global_value
to be declared volatile
?
int global_value = 0;
void foo () {
++ global_v
The only uses of volatile
involve longjmp
, signal handlers, memory-mapped device drivers, and writing your own low-level multi-threaded synchronization primitives. For this last use however, volatile
is not sufficient and may not even be necessary. You'll definitely also need asm (or compiler-specific or C1x atomics) for synchronization.
volatile
is not useful for any other purposes, including the code you asked about.