[fpc-devel] volatile variables
mschnell at lumino.de
Tue Jun 28 14:32:44 CEST 2011
On 06/28/2011 01:20 PM, Henry Vermaak wrote:
> "Operations on volatile variables are not atomic,
That is of course known.
> nor do they establish a proper happens-before relationship for threading.
I see. So maybe part of my question is invalid.
But as pthread_mutex (and the appropriate Windows stuff) contains a
memory barrier, same does enforce memory ordering even in an SMP
environment, regarding cache operations and with CPUs that do on-the fly
So, regarding C, I understand that (even in a single CPU environment):
If all accesses to a variable are protected by a MUTEX, multiple threads
will use the variable as expected, only if it is defined as volatile.
Otherwise is might be cached in registers and one thread's writing to (i
C code but not compiled that way) it might be unnoticed by the other thread.
Now how is the volatile state defined in Pascal and how can a heap
variable be defined to be handled as volatile ?
More information about the fpc-devel