What does an atomic test-and-set instruction do?
Correct answer A. Returns the old value of a memory word and sets it to true as one indivisible operation
test_and_set reads a boolean and writes true in a single hardware operation that cannot be interrupted or interleaved with another CPU's access. A lock built on it spins while the returned old value is true; a thread that gets back false has acquired the lock. Because the read and write are indivisible, two threads can never both see false and enter together.
Answer checked How we write and check questions
Discussion