volatile variables in D....

Sean Kelly sean at f4.ca
Thu Apr 12 08:18:48 PDT 2007


Sean Kelly wrote:
> Frank Benoit (keinfarbton) wrote:
>> is it this you are looking for?
>> http://www.digitalmars.com/d/statement.html#VolatileStatement
> 
> Technically no, but it should achieve the same thing.  Given the 
> functionality of the volatile statement in D:
> 
>     int* io = 0x1234;
>     int x;
> 
>     volatile x = *io;
> 
> implicitly guarantees that the load from *io will always occur from 
> memory rather than from a cached register value.  I know it's not as 
> convenient as labeling a variable as volatile as per C/C++, but it 
> should do.

Oh, if you're so inclined, tango.core.Atomic in Tango should achieve the 
same result, even though it's intended for multithreading as well.  Use 
"atomicLoad!(msync.raw)(val)" and it will always load 'val' from memory. 
  This module currently only supports x86 however.  If you (or anyone 
else) needs support for other platforms, please let me know.  And if 
you're really inclined, perhaps supply a .c or .S file with the stuff 
I'd need to call for that platform.


Sean



More information about the Digitalmars-d mailing list