GATE CSE 2020 Q44: What a semaphore barrier between code sections P and Q achieves
- Operating System
- 2 marks
- MCQ
- −2/3 if wrong
Question
Each of a set of processes executes the following code using two semaphores a and b initialized to 1 and 0, respectively. Assume that count is a shared variable initialized to 0 and not used in CODE SECTION P.
CODE SECTION P
wait(a); count=count+1;
if (count==n) signal(b);
signal(a); wait(b); signal(b);
CODE SECTION QWhat does the code achieve?
Try it: multiple choice: exactly one correct option
Show answer and explanation
Answer: A (official GATE 2020 final answer key)
Concept used: A barrier: a counter protected by a mutex, plus a turnstile semaphore opened when the last process arrives.
First step: b starts at 0, so every process blocks on wait(b) until count reaches n; then each passing process re-signals b for the next.
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 2020 CS question paper and final answer key, organised by IIT Delhi. 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