difference between x.atomicOp!"+="(1) and atomicFetchAdd(x, 1)?
mw
mingwu at gmail.com
Thu Nov 10 18:35:35 UTC 2022
On Thursday, 10 November 2022 at 18:30:16 UTC, Paul Backus wrote:
> On Thursday, 10 November 2022 at 17:04:31 UTC, mw wrote:
>> Hi,
>>
>> Anyone can help explain what is the difference between
>> x.atomicOp!"+="(1) and atomicFetchAdd(x, 1)?
>
> Looking at the source in druntime, `atomicOp!"+="` forwards to
> `atomicFetchAdd` internally, so they should have the same
> behavior.
Thanks! Indeed:
https://github.com/dlang/dmd/blob/master/druntime/src/core/atomic.d#L582
(source is always your best friend :-)
and looks like atomicFetchAdd is more fundamental:
```
return cast(T)(atomicFetchAdd(val, mod) + mod);
```
More information about the Digitalmars-d-learn
mailing list