implicit conversions to/from shared

ag0aep6g via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 11 07:19:23 PDT 2016


On 07/11/2016 03:23 PM, ag0aep6g wrote:
> I think I would prefer if the compiler would generate atomic operations,

Backpedaling on that one.

With automatic atomic loads and stores, one could accidentally write this:

     shared int x;
     x = x + 1; /* atomic load + atomic != atomic increment */

Easy to miss the problem, because the code looks so innocent.

But when the atomic loads and stores must be spelled out it would look 
like in my original post:

     shared int x;
     atomicStore(x, atomicLoad(x) + 1);

Way more obvious that the code isn't actually thread-safe.

So now I'm leaning towards requiring the verbose version.


More information about the Digitalmars-d mailing list