Fixing core.atomic

sarn sarn at theartofmachinery.com
Tue Jun 1 02:50:52 UTC 2021


On Sunday, 30 May 2021 at 20:58:56 UTC, IGotD- wrote:
> Definitely, the D atomic library is cumbersome to use. C++ 
> std::atomic supports operator overloading for example.
>
> atomicVar += 1;
>
> will create an atomic add as atomicVar is of the atomic type. D 
> doesn't have this and I think D should add atomic types like 
> std::atomic<T>.

That was a design choice.  It's because of this:

> I like this because then I can easily switch between atomic 
> operations and normal operations by just changing the type and 
> very few changes.

The trouble is that only works in a handful of simple cases 
(e.g., you just want a simple event counter that doesn't affect 
flow of control).  For anything else, you need to think carefully 
about exactly where the atomic operations are, so there's no 
point making them implicit.


More information about the Digitalmars-d mailing list