compare_exchange_weak atomically compares an atomic object with an expected value and, if they are equal, replaces the atomic value with a desired value.
If the comparison fails, the current atomic value is copied into expected.
Formally, for atomic object x, expected value e, and desired value d:
x=ex=e⟹x←d and return true⟹e←x and return false