3 ms·
From my understanding, the only thing volatile does (IIRC this is implementation specified as the standard is vague) is prevent the compiler from optimizing out
by auxym 2y ago
From my understanding, the only thing volatile does (IIRC this is implementation specified as the standard is vague) is prevent the compiler from optimizing out reads or writes when it thinks they are "useless". That is, is tells the compiler "this memory location may change independently of that the code is doing, so you always need to read or write it when I say so".
Atomicity is sort of a different thing. You might need things like critical sections (disable interrupts) or memory fencing for the read-modify-write cycle.