is increment on shared ulong atomic operation?

rsw0x via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 7 11:43:23 PST 2016


On Sunday, 7 February 2016 at 19:39:27 UTC, rsw0x wrote:
> On Sunday, 7 February 2016 at 19:27:19 UTC, Charles Hixson 
> wrote:
>> If I define a shared ulong variable, is increment an atomic 
>> operation?
>> E.g.
>>
>> shared ulong t;
>>
>> ...
>>
>> t++;
>>
>> It seems as if it ought to be, but it could be split into 
>> read, increment, store.
>>
>> I started off defining a shared struct, but that seems silly, 
>> as if the operations defined within a shared struct are 
>> synced, then the operation on a shared variable should be 
>> synced, but "+=" is clearly stated not to be synchronized, so 
>> I'm uncertain.
>
> https://dlang.org/phobos/core_atomic.html#.atomicOp

Just noticed that there's no example.
It's used like

shared(ulong) a;
atomicOp!"+="(a, 1);


More information about the Digitalmars-d-learn mailing list