public bool CompareAndExchange (bool expected, bool newVal) { int newTemp = newVal ? Set : UnSet; int expectedTemp = expected ? Set : UnSet; return AotInterlocked.CompareExchange (ref flag, newTemp, expectedTemp) == expectedTemp; }