GATE CSE 2024 Session 2 Q46: Possible outcomes of two threads using two semaphores
- Operating System
- 2 marks
- MSQ
- No negative marking
Question
Consider a multi-threaded program with two threads T1 and T2. The threads share two semaphores: s1 (initialized to 1) and s2 (initialized to 0). The threads also share a global variable x (initialized to 0). The threads execute the code shown below.
// code of T1
wait(s1);
x = x+1;
print(x);
wait(s2);
signal(s1);
// code of T2
wait(s1);
x = x+1;
print(x);
signal(s2);
signal(s1);Which of the following outcomes is/are possible when threads T1 and T2 execute concurrently?
Try it: multiple select: one or more correct options
Show answer and explanation
Answer: B, C (official GATE 2024 final answer key)
Concept used: Waiting on a semaphore while holding a mutex that the signalling thread needs causes deadlock.
First step: If T1 gets s1 first, it blocks on wait(s2) still holding s1, and T2 can never pass wait(s1).
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 2024 Session 2 CS question paper and final answer key, organised by IISc Bangalore. 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