compare and swap vs test and set

Tony The Lion picture Tony The Lion · Sep 7, 2010 · Viewed 18.7k times · Source

Could someone explain to me the working and differences of above operations in multi-threading?

Answer

Kirill V. Lyadvinsky picture Kirill V. Lyadvinsky · Sep 7, 2010

test-and-set modifies the contents of a memory location and returns its old value as a single atomic operation.

compare-and-swap atomically compares the contents of a memory location to a given value and, only if they are the same, modifies the contents of that memory location to a given new value.

The difference marked in bold.