Atomically compares the atomic value with that of expected. If those are bitwise-equal, replaces the former with desired
(performs read-modify-write operation). Otherwise, loads the actual atomic value stored into expected (performs load operation).
compare_exchange_weak is allowed to fail spuriously, that is, acts as if atomic value != expected even if they are equal.
When a compare-and-exchange is in a loop, compare_exchange_weak will yield better performance on some platforms.
Atomically compares the atomic value with that of expected. If those are bitwise-equal, replaces the former with desired (performs read-modify-write operation). Otherwise, loads the actual atomic value stored into expected (performs load operation).
compare_exchange_weak is allowed to fail spuriously, that is, acts as if atomic value != expected even if they are equal. When a compare-and-exchange is in a loop, compare_exchange_weak will yield better performance on some platforms.