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

Iain Buclaw via D.gnu d.gnu at puremagic.com
Wed Jul 16 06:41:42 PDT 2014


On 16 July 2014 14:10, Johannes Pfau via D.gnu <d.gnu at puremagic.com> wrote:
> Am Wed, 16 Jul 2014 05:53:30 +0000
> schrieb "Timo Sintonen" <t.sintonen at luukku.com>:
>
>> On Tuesday, 24 June 2014 at 14:14:18 UTC, Johannes Pfau wrote:
>>
>> > I think we should at least try to bring this to the main
>> > newsgroup,
>>
>> I told you this is not going to work. The decision seems to be
>> made even when the conversion is still going on. Lets just make
>> this into gdc so we can continue the real work. When this is
>> ready and working, we may try again.
>>
>> Unfortunately I am not skilled enough to implement this into the
>> compiler so I have to ask somebody else to do it. I will test it
>> as soon it is possible.
>>
>> This has even more importance now because I have understood that
>> dmd will disallow read-modify-write access to shared variables. I
>> hope this feature is not brought to gdc before volatile is
>> working.
>>
>
> I didn't have any high expectations, nevertheless we had to try.
>
> Well I could implement the DIP for GDC, but this is against the vision
> of a shared frontend. In the end Iain has to decide what to do.
>
> I'm not sure if I'd implement Volatile!T though. It's probably lots of
> work and there's no guarantee it'll work at all in the end. The more I
> think about it the more corner cases come to mind which all need to be
> worked around.
>
> Keeping only peek/poke as Walter suggests of course also has drawbacks.
> peek/poke plus Mike's wrapper is probably the best we'll get from DMD.
>
> Btw: @Iain if we implement these peek/poke things I think
> asm{"" : : :"memory";} is not good enough. At least it's being removed
> in some tests and according to some sources it only affect operations
> on volatile variables... So we'd have to implement peek/poke on top of
> C/GCC volatile.

Wouldn't a reinterpret cast (VIEW_CONVERT_EXPR) to volatile be enough?

Something akin to:

T peek(T var) { return *(volatile T*)&var; }
T poke(T var, T val) { return *(volatile T*)&var = *(volatile T*)&val; }


More information about the D.gnu mailing list