Practice free →
HomeGATE CSEcomputerscienceOperating Systems › The COMPARE-AND-SWAP (CAS) instruction is more p…

The COMPARE-AND-SWAP (CAS) instruction is more powerful than $TAS$ because it

Awrites only if current value matches expected
Balways succeeds in writing
Cdoesn't require any hardware support
Dblocks indefinitely on contention
Answer & Solution
Correct answer: A. writes only if current value matches expected
1. OSTEP §28.10 describes CAS: $CAS(\&L, expected, new)$: - Reads the current value at $\&L$. - If it equals $expected$, writes $new$ and returns TRUE. - Otherwise leaves it unchanged and returns FALSE. 2. This conditional swap enables LOCK-FREE programming: many threads can attempt CAS, and only one will succeed at a time (whoever's $expected$ matches). 3. CAS is the foundation for lock-free data structures (queues, stacks, hash tables) — used widely in Linux kernel and JVM. 4. Options B, C, D misdescribe CAS's behavior. _Source: OSTEP Ch 28, §28.10 (Compare-And-Swap), p. 7-8._
Solve this in the app — GATE CSE practice & 24k+ MCQs →
Related questions