Lukas' Notes

concurrency cpp

Definition

compare_exchange_weak

bool compare_exchange_weak( T& expected, T desired,
                            std::memory_order success,
                            std::memory_order failure ) noexcept;

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 :