GATE / CS ARCHIVE

GATE CSE 2002 / QUESTION 18(b)(ii)

Progress guarantees of a test-and-set spinlock

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

GATE 2002, Q18(b)(ii) Descriptive
Report issue

Synchronization & Concurrency

Question 18(b)(ii), GATE 2002: Atomic TEST_AND_SET(int*x) performs A1:y=*x; A2:*x=1; A3:return y. Shared mutex initially 0. Entry/exit templates: void enter_cs(){while(blank);} void leave_cs(){blank;} Original18(b)(ii): For the resulting spinlock entry/exit solution, determine whether it is deadlock-free and starvation-free.
Question 18(b)(ii), GATE 2002: Atomic TEST_AND_SET(int*x) performs A1:y=*x; A2:*x=1; A3:return y. Shared mutex initially 0. Entry/exit templates: void enter_cs(){while(blank);} void leave_cs(){blank;} Original18(b)(ii): For the resulting spinlock entry/exit solution, determine whether it is deadlock-free and starvation-free.
Question 18(b)(ii), GATE 2002: Atomic TEST_AND_SET(int*x) performs A1:y=*x; A2:*x=1; A3:return y. Shared mutex initially 0. Entry/exit templates: void enter_cs(){while(blank);} void leave_cs(){blank;} Original18(b)(ii): For the resulting spinlock entry/exit solution, determine whether it is deadlock-free and starvation-free.
Question 18(b)(ii), GATE 2002: Atomic TEST_AND_SET(int*x) performs A1:y=*x; A2:*x=1; A3:return y. Shared mutex initially 0. Entry/exit templates: void enter_cs(){while(blank);} void leave_cs(){blank;} Original18(b)(ii): For the resulting spinlock entry/exit solution, determine whether it is deadlock-free and starvation-free.
Question 18(b)(ii), GATE 2002: Atomic TEST_AND_SET(int*x) performs A1:y=*x; A2:*x=1; A3:return y. Shared mutex initially 0. Entry/exit templates: void enter_cs(){while(blank);} void leave_cs(){blank;} Original18(b)(ii): For the resulting spinlock entry/exit solution, determine whether it is deadlock-free and starvation-free.
Tap to enlarge
Answer & solution

Answer: Deadlock-free under the usual progress assumptions; not starvation-free. (no official key was published)

With atomic TEST_AND_SET, one contender acquires any free lock, and a holder that finishes its finite critical section releases the lock. Under the usual assumptions that a holder continues to receive execution time and eventually exits, the lock is deadlock-free: processes do not remain mutually blocked with no one able to proceed. It is not starvation-free, since a waiting process is not assigned a turn. Each time the lock is released another contender can acquire it first, so one process can lose indefinitely even while other processes keep making progress. As with any spinlock, a scheduler that prevents the holder from running can itself defeat progress; deadlock-freedom is not an unconditional scheduling guarantee.

Original paper, page 9