CS FundamentalsVery hardGATE CS · Amazon/Microsoft SDE MCQ
Why is a test-and-test-and-set spinlock (spin on a plain read, and only try the atomic exchange when the lock looks free) usually faster than spinning directly on test-and-set on a multicore machine?
- A. It guarantees FIFO fairness among all the waiting threads
- B. Spinning on reads stays in the local cache instead of flooding the bus
- C. It disables interrupts while spinning, so no context switch can occur
- D. It avoids the need for any atomic read-modify-write instruction at all
Correct answer: B. Spinning on reads stays in the local cache instead of flooding the bus
Each test-and-set is a write that invalidates the line in every other cache, so spinning on it causes constant coherence traffic. Spinning on a read stays in the local cache until the holder's release invalidates it. It is still unfair and still needs the atomic step.
More Operating Systems questions
- 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…
- 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…