Fixing core.atomic

IGotD- nise at nise.com
Mon May 31 08:52:33 UTC 2021


On Monday, 31 May 2021 at 08:18:35 UTC, Guillaume Piolat wrote:
>
> I have once implemented an atomic struct like this and the 
> first thing that happened is that you would write:
>
>
> s = s + 1;
>
> Breaking atomicity.

Yes, so the programmers must be aware of this. In C++ only the 
unary -= and += are supported and -- and ++.

Is it possible to overload binary operators so that they cause an 
compiler error? In order achieve the same s = s + 1; you need to 
write.

s.store(s.load() + 1)

However, the assignment operator writing s = 1 is nice instead of 
s.store(1).


More information about the Digitalmars-d mailing list