[Bug 126] Add support for attribute to mark data as volatile.

Timo Sintonen via D.gnu d.gnu at puremagic.com
Tue Jun 24 03:46:11 PDT 2014


To keep this thread going, I had a quick look at the reference 
material of the dip and picked some thoughts.

In some languages volatile has a stronger meaning, like 
guaranteeing an atomic access. In some languages it may not 
guarantee anything.

In this proposal volatile is only for optimization, not for 
protection. It does not add any code, it just prevents the 
optimizer removing some code.

Read-modify-write and multi-word access are not guaranteed. The 
user should be aware of possible failures and for example avoid 
longer data types than the word size of the processor.

Volatile is never recommended to use for communicatin between 
threads. It has been mentioned to be a reasonably good method to 
exchange data with an interrupt program. It is the only 
reasonable way to access hardware registers. The only others I 
have seen are library functions and inline assembly and they are 
not acceptable.


Walter has been against this and now also Martin. I think there 
is no use to bring this to the main forum. I understand the point 
that it is not very good to have something in the language specs 
that can not be guaranteed.

We just need this to access registers. Dmd is more for desktop 
and servers. It will never support all the targets gcc can. Could 
we make this a gdc extension?

While writing this  it just popped to my mind: if volatile is not 
good, could we reuse the 'system' word? Then it would be clear 
that this is for accessing system resources and not for 
application level.

There seems not to be much documentation about system. Tdpl says 
it may omit some checks and the website says it is quite the same 
than not having any other attributes. So:
What system means in general?
What it currently means in gdc?
Could we use it instead of volatile?


More information about the D.gnu mailing list