CS FundamentalsVery hardGATE CS · Amazon/Microsoft SDE MCQ
A lock-free stack pops with CAS(&top, old, old->next). Thread 1 reads top = A (A->next = B) and is delayed; thread 2 pops A, pops B, then pushes A back. Thread 1's CAS now succeeds. What is wrong?
- A. Nothing, because CAS guarantees the stack stays consistent
- B. The CAS keeps failing forever, so the threads livelock
- C. Top becomes B, a node no longer in the stack (the ABA problem)
- D. Thread 1 pops A twice, so the stack gains a duplicate node
Correct answer: C. Top becomes B, a node no longer in the stack (the ABA problem)
CAS checks only that top still equals A, not that the stack is unchanged. Thread 1 installs its stale A->next = B, re-linking a freed node. Tagged pointers (version counters) or hazard pointers avoid ABA.
More Operating Systems questions
- A low-priority task L holds a mutex. High-priority H blocks on it, and medium-priority M (which does not need the mutex) becomes ready…
- A semaphore S starts at 7. Over time 20 wait() and 15 signal() operations complete on it, in some order, with no process left blocked at…
- A Unix process opens a file, forks, and both parent and child each write 100 bytes to the inherited descriptor (no OAPPEND, no seeks), one…
- Which statement about the convoy effect is correct?
- Disk cylinders 0–199; the head is at 120 moving toward 199; requests: 10, 22, 20, 2, 40, 6, 38. Counting the return jump as head movement…
- Which property of a journaling file system's ordered mode is correct?