GATE CSE 2022 Q19: Semaphore initialisation that prints BCABCA...
- Operating System
- 1 mark
- MCQ
- −1/3 if wrong
Question
Consider the following threads, , , and executing on a single processor, synchronized using three binary semaphore variables, , , and , operated upon using standard wait() and signal(). The threads can be context switched in any order and at any time.
| T1 | T2 | T3 |
|---|---|---|
| while(true){ | while(true){ | while(true){ |
| wait(S3); | wait(S1); | wait(S2); |
| print("C"); | print("B"); | print("A"); |
| signal(S2); } | signal(S3); } | signal(S1); } |
Which initialization of the semaphores would print the sequence BCABCABCA….?
Try it: multiple choice: exactly one correct option
Show answer and explanation
Answer: C (official GATE 2022 final answer key)
Concept used: To force a strict order, exactly the semaphore guarding the first thread to run should start at 1.
First step: B must print first, so only may pass its wait initially: which semaphore does wait on?
Full step-by-step solution
Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.
Share this question
Source: official GATE 2022 CS question paper and final answer key, organised by IIT Kharagpur. Question paper · Answer key
More Operating System PYQs
- 2026 Session 1 · Q29False statements about deadlocks
- 2026 Session 1 · Q35Minimum resource instances for deadlock freedom (5 processes, max 2)
- 2026 Session 1 · Q59Disk transfer time for random sectors on tracks 5, 12, 7
- 2026 Session 1 · Q63Number of printf calls with fork, continue and break
- 2026 Session 1 · Q64Average FCFS waiting time for alternating A and C processes
- 2026 Session 2 · Q23CPU scheduling algorithm that cannot be preemptive