c/atomic/atomic compare exchange

Atomically compares the contents of memory pointed to by with the contents of memory pointed to by, and if those are bitwise equal, replaces the former with  (performs read-modify-write operation). Otherwise, loads the actual contents of memory pointed to by into  (performs load operation).

The memory models for the read-modify-write and load operations are and  respectively. The (1-2) versions use memory_order_seq_cst by default.

The weak forms ((2) and (4)) of the functions are allowed to fail spuriously, that is, act as if even if they are equal. When a compare-and-exchange is in a loop, the weak version will yield better performance on some platforms. When a weak compare-and-exchange would require a loop and a strong one would not, the strong one is preferable.

Return value
The result of the comparison: if  was equal to,  otherwise.