Here&#x27;s just to back up atomic_cheese&#x27;s answer with some references:<p>Atomically, compares the contents of the memory pointed to by object or by this for equality
with that in expected, and if true, replaces the contents of the memory pointed to by object or by
this with that in desired, and if false, updates the contents of the memory in expected with the
contents of the memory pointed to by object or by this.<p><a href="http:&#x2F;&#x2F;open-std.org&#x2F;JTC1&#x2F;SC22&#x2F;WG21&#x2F;docs&#x2F;papers&#x2F;2011&#x2F;n3242.pdf" rel="nofollow">http:&#x2F;&#x2F;open-std.org&#x2F;JTC1&#x2F;SC22&#x2F;WG21&#x2F;docs&#x2F;papers&#x2F;2011&#x2F;n3242.pd...</a><p>Atomically compares the object representation of <i>this with the object representation of expected, as if by std::memcmp, and if those are bitwise-equal, replaces the former with desired (performs read-modify-write operation). Otherwise, loads the actual value stored in </i>this into expected (performs load operation). Copying is performed as if by std::memcpy.<p><a href="http:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;atomic&#x2F;atomic&#x2F;compare_exchange" rel="nofollow">http:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;atomic&#x2F;atomic&#x2F;compare_excha...</a>