http://atfykf7jyn4uxuwdqmonyz4xohrw5mrnrldkwtulxkpictxrm3xxfsyd.onion/@tylerneely/fear-and-loathing-in-lock-free-programming-7158b1cdd50c
The return value varies across implementations, but a good implementation clearly indicates success or failure. CAS(variable, old, new) is the shorthand I will use. If variable is set to 0 then CAS(variable, 0, 1) would succeed, as long as another thread didn’t change the value while we weren’t looking.