how to stop a variable from being optimized out
Rory via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Feb 23 22:29:33 PST 2015
Hi,
Is there a way I can stop "current" from being optimized out
without using "volatile"?
The compiler is suggesting I replace "volatile" with
"synchronized" but I don't want it synchronized?
Would a memory barrier work?
shared n = new int(value);
for (;;) {
volatile auto current = payload; // payload is a shared variable
if (current == payload) { // just to make sure we copied a
complete value from
if (current is null) {
if (cas(&payload, current, n)) {
return true;
}
}
}
}
Thanks!
-Rory
More information about the Digitalmars-d-learn
mailing list