Very limited shared promotion

aliak something at something.com
Mon Jun 24 12:12:57 UTC 2019


On Monday, 24 June 2019 at 11:38:29 UTC, aliak wrote:
> On Monday, 24 June 2019 at 02:55:39 UTC, Walter Bright wrote:
>> On 6/23/2019 7:42 PM, Timon Gehr wrote:
>>> [...]
>>
>> The reference to shared i does not extend past the end of the 
>> function call. That doesn't mean the cached value of i is 
>> propagated to all other threads.
>>
>>     int x;
>>     void fun(scope ref shared(int) x) {
>>         x = 3; // (*)
>>     } // end of reference to x is guaranteed
>>     assert(x == 3); // all caches not updated, assert is not 
>> guaranteed
>>
>> (*) now replace this with a call to another thread to set x to 
>> 3.
>
> You can assign to a shared primitive without a compilation 
> error?
>
> Does the compiler do the necessary synchronization under the 
> hood?
>
> I would've assumed you'd have to use atomicStore or the like?

ok so I guess you can indeed do that: 
https://d.godbolt.org/z/Ge7bTc

Is that intended behavior? I would've expected an `xchg` or  lock 
xchg or something?


More information about the Digitalmars-d mailing list