compare and swap vs test and set
问题 Could someone explain to me the working and differences of above operations in multi-threading? 回答1: 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. 回答2: Test and set operates on a bit, compare and swap operates