[fpc-devel] volatile variables
DrDiettrich1 at aol.com
Tue Jun 28 23:29:52 CEST 2011
Vinzent Höfler schrieb:
> On Tue, 28 Jun 2011 15:54:35 +0200, Michael Schnell <mschnell at lumino.de>
>> But if you do the same with
>> volatile static int x;
>> the code will stay and another thread can watch x growing in a time
>> sharing system.
> No, it can't. "volatile" just ensures that accessing the variable
> results in
> actual memory accesses. That does not mean cache-coherence, so another core
> may still see other (as in "older") values.
I dare to disagree. When reading a volatile variable requires a memory
(RAM) read in one core, it will require the same read in any other core,
and updates have to occur in write-through into the RAM.
A difference could occur only, when the "memory" access may end up in
the cache instead of in RAM. Question is, what makes one variable use
read/write-through, while other variables can be read from the cache,
with lazy-write? Is this a compiler requirement, which has to enforce
read/write-through for all volatile variables? But if so, which
variables (class fields...) can ever be treated as non-volatile, when
they can be used from threads other than the main thread?
More information about the fpc-devel