GATE / CS ARCHIVE

GATE CSE 2022 / QUESTION 19

GATE CSE 2022 Q19

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

GATE 2022, Q19 1 mark · MCQ
Report issue

Synchronization & Concurrency

Question 19, GATE 2022: Three infinite threads run on one CPU with binary semaphores. T1 repeats wait(S3); print C; signal(S2). T2 repeats wait(S1); print B; signal(S3). T3 repeats wait(S2); print A; signal(S1). Which initialization forces BCABC… despite arbitrary context switches? A (S1,S2,S3)=(1,1,1); B (1,1,0); C (1,0,0); D (0,1,1).
Tap to enlarge
Your answer
Answer & solution

Official answer: C

T2 waits on S1 and prints B, then signals S3. T1 waits on S3 and prints C, then signals S2. T3 waits on S2 and prints A, then signals S1. Initialize only S1 to 1, with S2=S3=0, to force B→C→A repeatedly. That is C. This assumes ordinary successful semaphore operations and eventual scheduling of enabled threads.

Track the unique token: (1,0,0) enables only T2. Its wait consumes S1 and its signal creates the S3 token; then T1 creates S2; then T3 restores S1. Context switching can delay progress, but cannot permit a different letter while its semaphore is zero.

Original paper, page 15 · Answer key