GATE CS 2015 Set 3 — Question 31
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.MCQ+1 / -0.33MediumRace Conditions & Critical SectionProcess SynchronizationOperating SystemDeadlocks
Operating System → Deadlocks → Race Conditions & Critical Section
Last updated
Question
Two processes and need to access a critical section. Consider the following synchronization construct used by both the processesProcess X
Process Y
Here,
/* other code for process X */
while(true)
{
varP = true;
while(varQ == true)
{
/* Critical Section */
varP = false;
}
}
/* other code for process X */
/* other code for process Y */
while(true)
{
varQ = true;
while(varP == true)
{
/* Critical Section */
varQ = false;
}
}
/* other code for process Y */
varP and varQ are shared variables and both are initialized to false. Which one of the following statements is true?Correct answer
(A) The proposed solution prevents deadlock but fails to guarantee mutual exclusion
Solution
Let's analyze the execution trace:
1.Initially
varP = false, varQ = false.2.Process X executes
varP = true.3.Context switch to Process Y.
4.Process Y executes
varQ = true.5.Process Y checks
while(varP == true). Since varP is true, Y enters the Critical Section (CS).6.Context switch to Process X.
7.Process X checks
Both processes are in the Critical Section simultaneously, so Mutual Exclusion is violated.Regarding Deadlock: Deadlock implies processes are waiting indefinitely for a condition that will never become true. Here, processes do not wait; they enter the CS (incorrectly) or loop. If executed sequentially (e.g., X runs alone), X sets while(varQ == true). Since varQ is true, X enters the Critical Section (CS).varP=true, checks varQ (false), skips the inner loop (CS), and repeats. While this might be a liveness issue (starvation/livelock), it is not a deadlock in the sense of circular wait preventing any progress. The primary failure is Mutual Exclusion. The option stating it prevents deadlock but fails mutual exclusion is the most appropriate description of the race condition allowing both to enter.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 Deadlocks
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…