GATE / CS ARCHIVE

GATE CSE 2009 / QUESTION 33

Test-and-set spinlock guarantees

Operating Systems · Synchronization & Concurrency · Full GATE CSE 2009 paper

GATE 2009, Q33 2 marks · MCQ
Report issue

Synchronization & Concurrency

Question 33, GATE 2009: Shared lock X starts 0. enter_CS spins while atomic test-and-set(X) returns true; leave_CS writes X=0. Assess I deadlock-free; II starvation-free; III FIFO entry; IV multiple simultaneous entrants. A I only; B I/II; C II/III; D IV only.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Atomic test-and-set allows exactly one contender to observe 0 and enter, preserving mutual exclusion. When the current holder eventually leaves and resets X, some contender can acquire it, so the lock is deadlock-free under ordinary progress assumptions. There is no FIFO order or bounded-wait guarantee: the same process can repeatedly win and starve another. Only I holds, A. X denotes shared lock storage in this pseudocode, not an ordinary pass-by-value C local.

The atomic operation returns the old flag and sets it to 1 as one indivisible action. Only one contender can see old 0, so IV is false. Once the holder releases, some waiting process can succeed, assuming the holder and scheduler make ordinary progress; this supplies deadlock freedom. But no queue orders contenders. A newly arriving or repeatedly scheduled process can keep winning before another waiter, defeating both FIFO and starvation freedom. Therefore only I is justified.

Original paper, page 8