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 , expected value , and desired value :