Improve the ergonomics of core.atomic

Jackel jackel at gmx.com
Thu Oct 1 14:35:01 UTC 2020


On Thursday, 1 October 2020 at 13:27:46 UTC, IGotD- wrote:
> Currently the core.atomic library just adds template functions 
> for atomic operations and not a special atomic type. This 
> forces the programmer to use long a rather ugly template 
> operations through out the entire code.
>
> Typically
>
> atomicOp!"+="(v1, v2);
>
> This is nice for casual atomic operations but ugly and a pain 
> for many atomic operations.
>
> Why hasn't D just like C++ an atomic type. In C++ you simply 
> declare.
>
> std::atomic<int> var;
>
> and then use the operator overload.
>
> var += 1;
>
> which will trickle down to var.fetch_add(1);
>
> This makes much nicer in the code. Also if you want swap 
> between non atomic operations and atomic operations, you have 
> to change less.
>
> What D needs is just like in C++ an atomic template type.

One reason could be that it is much more obvious what operations 
are atomic when reading. The syntax isn't as nice, but you know 
the operation is atomic.



More information about the Digitalmars-d mailing list