Your ignoring the return value of compare and set. It will never fail because it is single threaded, but if this were an attempt to handle it correctly this would have to be in a loop that retries if actions were taken based on the an old value. The loop isn't necessarily idempotent either.