Re: Simultaneous Writes on Volatile

FredK wrote:
.... ... ...

My general concern here is that the discussion itself confuses people reading that volatile is something that does something other than the above, or something they should even care about. If you need to write a driver, or a shared memory application - you need to care about it and a 1000 other things. Otherwise you don't - and the initial example is an example of a meaningless useage of volatile. The question of so-called simultanious access to memory in the context given is outside the scope of the C language definition. Were someone to invent HW and a parallelizing C compiler to go with it - the issues of correct operation would be up to the implementation to guarantee - not the programmer writing the C application.
What is your expectation for the number of reads of 'x' in:

volatile int x = 1;
int y = x + x;

? Can one have a general expectation regardless of implementation and hardware? What does your experience of >= 32 years suggest?

If someone expects 2 reads of 'x' above, is that expectation consistent with a general expectation that every reference (of any object) that implies a read "should" result in an independent read, but a compiler can typically optimize out such multiple reads where there is no 'volatile' qualifier?

These questions are a shift away from the original(s), but what you share about your familiarity with 'volatile' can serve as a reference for others, if you'd care to. Thanks, FredK.

Relevant Pages