LDC optimized builds causing unexpected behaviour when sharing variable between threads

rm rdm at e.email
Mon Jun 6 08:08:45 UTC 2022


On 02/06/2022 20:41, Keivan Shah wrote:
> On Thursday, 2 June 2022 at 11:56:07 UTC, Johan wrote:
>> `atomicFence` only works for ordering memory operations on a single 
>> thread, not ordering between threads.
>>
>> You can either use a mutex (to coordinate between threads), or need 
>> all store/loads to be atomic with `atomic{Store,Load}`.
>> I am surprised that there is no `core.atomic!int` to simplify your 
>> life. Perhaps you should make a feature request :)
>>
>> -Johan
> 
> Hey Johan,
> Thanks for the reply, I finally ended up using `atomic{Store,Load}` with 
> some memory ordering after reading about them a bit. Atomic variables 
> (`core.atomic!int`) would have been a great feature, I have no further 
> usecases for them and they probably are a bit more complex for my 
> understanding to make a informed request right now, but will definitely 
> make one when my understanding improves in the future.
> 
> Thanks and regards,
> Keivan Shah.

You can check this:
https://github.com/rymrg/drm/blob/main/atomic.d

It works well enough for my needs at the moment. But it requires more 
extensive testing to see if it plays nicely with @safe. But for 
__gshared it should work just fine.


More information about the digitalmars-d-ldc mailing list