http://atfykf7jyn4uxuwdqmonyz4xohrw5mrnrldkwtulxkpictxrm3xxfsyd.onion/@tylerneely/fear-and-loathing-in-lock-free-programming-7158b1cdd50c
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. Then CAS(variable, 1, 0) would set it back. But CAS(variable, "hot garbage", 0) would not work unless one of our thread friends has given variable a surprise hot-garbage makeover ;) If several threads try to do CAS(variable, 0, 1) at the same time when the value was set to 0 , only one of them will succeed.