GATE CS 2020 Set 1 — Question 44
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.MCQ+2 / -0.67MediumSemaphoresProcess SynchronizationOperating System
Operating System → Process Synchronization → Semaphores
Last updated
Question
Each of a set of processes executes the following code using two semaphores and initialized to 1 and 0, respectively. Assume that What does the code achieve?
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 Q
Correct answer
(A) It ensures that no process executes CODE SECTION Q before every process has finished CODE SECTION P.
Solution
The code implements a barrier synchronization mechanism.
1.Entry Section (Mutex on count):
-
wait(a)andsignal(a)protect the update of the shared variablecount. - Each process increments
countto indicate it has arrived at the barrier (finished the work in Section P).
- The first processes increment
count, releasea, and then executewait(b). Since is initialized to 0, they block. - The -th (last) process increments
countto . The conditionif (count==n)becomes true, so it executessignal(b).
- The
signal(b)by the last process wakes up one waiting process. - That woken process proceeds to execute
signal(b)(the last statement), which wakes up the next waiting process, and so on (cascading signals). - This ensures that no process can pass the
wait(b)statement (and enter CODE SECTION Q) until the last process has arrived and executed the firstsignal(b).
Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE CS question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
More questions on Process Synchronization
2026 Set 2 Q23Which one of the following CPU scheduling algorithms cannot be preemptive?2026 Set 1 Q29With respect to deadlocks in an operating system, which of the following statements is/are FALSE?2026 Set 1 Q31In the context of relational database normalization, which of the following statements is/are true?2026 Set 1 Q35Consider a system consisting of instances of a resource , being shared by 5 processes.…2026 Set 2 Q51Consider three processes P1, P2, and P3 running identical code, as shown in the pseudocode below. A…