Practice mode Operating Systems

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

Explanation

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.