Volatile has nothing to do with reads/writes being atomic AFAIK.matt42 wrote:OK so if I specify a volatile float then I can expect single load/stores to be atomic.
For atomic reads and writes the variables just need to be naturally aligned, which they will be for 4 byte size variables unless you actually messed with the default alignment settings.
The 'volatile' keyword does 2 things...
1. It stops a variable from being held in a register so that whenever it is referenced it is always read from memory. Basically it tells the compiler "this variable can be modified by multiple threads so to make sure you always have the latest value you must access it from memory"
2. It prevents the compiler from reordering it with respect to code around it, so things are always done in the order you have written.