Is comparison of shared data thread-safe?
Nick Treleaven
nick at geany.org
Thu Mar 16 12:32:34 UTC 2023
With -preview=nosharedaccess, I get:
int y = 2;
shared int x = y; // OK
assert(x == 2); // no error
y = x; // error
So for the assignment to y, reading x is an error and atomicLoad
should be used instead. But is it an oversight that reading x in
the assert is not an error?
I have also found this in a unittest in core.atomic:
shared(size_t) i;
atomicOp!"+="(i, cast(size_t) 1);
assert(i == 1);
Is the assert somehow thread-safe?
More information about the Digitalmars-d-learn
mailing list