<p dir="ltr">On 4 Jul 2015 00:50, "rsw0x via Digitalmars-d" <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br>
><br>
> On Friday, 3 July 2015 at 17:51:17 UTC, Iain Buclaw wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I'm currently re-writing core.atomics for GDC to switch from the old GCC __sync_* builtins to the new (more compatible with how core.atomics is supposed to function) __atomic_* builtins.<br>
>><br>
>> <a href="https://github.com/D-Programming-GDC/GDC/pull/111">https://github.com/D-Programming-GDC/GDC/pull/111</a><br>
>><br>
>> One thing I've noticed in my reading of this, is that the following are accepted as valid, but makes no sense.<br>
>><br>
>> ---<br>
>> atomicStore!(MemoryOrder.acq)(var, val);<br>
>><br>
>> var = atomicLoad!(MemoryOrder.rel)(val);<br>
>> ---<br>
>><br>
>> I'd like to suggest that it should be considered completely valid for both cases to throw a compilation error (using static assert).  However I'd like the core druntime team to be on board with this.<br>
>><br>
>> Regards<br>
>> Iain.<br>
><br>
><br>
> IIRC these flat out error on LDC, I meant to submit a bug report but I forgot until I read this.</p>
<p dir="ltr">Good to know, as I understand it, there's currently the following behaviour in dmd runtime.</p>
<p dir="ltr">atomicLoad!(Memoryorder.seq)  ->  issues a lock+exchange.<br>
atomicLoad!(Memoryorder.acq)  ->  lock-free (only because of x86 guarantees).<br>
atomicLoad!(Memoryorder.rel)  ->  issues a lock+exchange.<br>
atomicLoad!(Memoryorder.raw)  ->  no lock.</p>
<p dir="ltr">atomicStore!(Memoryorder.seq)  ->  issues a lock+exchange.<br>
atomicStore!(Memoryorder.acq)  ->  issues a lock+exchange.<br>
atomicStore!(Memoryorder.rel)  ->  lock-free (only because of x86 guarantees). <br>
atomicStore!(Memoryorder.raw)  ->  no lock.</p>
<p dir="ltr">Is it fine to consider the following (for optimisation purposes, of course :)</p>
<p dir="ltr">atomicLoad!(Memoryorder.seq)  ->  Can be lock-free (only because of x86 guarantees), but guaranteed to do the right thing otherwise.<br>
atomicLoad!(Memoryorder.acq)  ->  Can be lock-free (only because of x86 guarantees), but guaranteed to do the right thing otherwise.<br>
atomicLoad!(Memoryorder.rel)  ->  static assert.<br>
atomicLoad!(Memoryorder.raw)  ->  no lock.</p>
<p dir="ltr">atomicStore!(Memoryorder.seq)  ->  Can be lock-free (only because of x86 guarantees), but guaranteed to do the right thing otherwise.<br>
atomicStore!(Memoryorder.acq)  ->  static assert.<br>
atomicStore!(Memoryorder.rel)  ->  Can be lock-free (only because of x86 guarantees), but guaranteed to do the right thing otherwise. <br>
atomicStore!(Memoryorder.raw)  ->  no lock.</p>
<p dir="ltr">Iain.</p>