GATE CS 2019 Set 1 — Question 33
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.NAT+1 / -0HardRace Conditions & Critical SectionProcess SynchronizationOperating System
Operating System → Process Synchronization → Race Conditions & Critical Section
Last updated
Question
Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100.
The processes are executed on a uniprocessor system running a time-shared operating system. If the minimum and maximum possible values of D after the three processes have completed execution are X and Y respectively, then the value of Y – X is __________.
| P1 | P2 | P3 |
|---|---|---|
| : | : | : |
| D = D + 20 | D = D - 50 | D = D + 10 |
| : | : | : |
Correct answer
80 to 80
Solution
To find the minimum and maximum possible values of the shared variable after the execution of the three concurrent processes, we must analyze the read-modify-write operations at the assembly level. Each high-level statement
Thus, the minimum possible value of is:---
Thus, the maximum possible value of is:---
Can we achieve a higher value than ?
Suppose P1 and P3 both execute their reads when .
D = D + value is translated into three machine instructions:1.Read: Load the value of from memory into a local register .
2.Modify: Perform the arithmetic operation on .
3.Write: Store the value of back into the memory location of .
Let the initial value of be . The three processes perform the following operations:- P1: (Local register )
- P2: (Local register )
- P3: (Local register )
1. Finding the Minimum Value ()
To minimize the final value of , we want the largest increment (which is from P1) to be overwritten/lost, while ensuring the decrement ( from P2) is successfully applied.Consider the following interleaving sequence:1.P1 reads into .
2.P1 is preempted before writing.
3.P3 runs to completion:
- Reads .
- Updates .
- Reads .
- Updates .
- It calculates .
- It writes . (At this point, the updates of P3 and P2 are overwritten).
1.P2 reads into .
2.P2 is preempted before modifying/writing.
3.P1 runs to completion:
- Reads .
- Updates .
- Reads .
- Updates .
- It decrements its local copy: .
- It writes .
Thus, the minimum possible value of is:---
2. Finding the Maximum Value ()
To maximize the final value of , we want the decrement ( from P2) to be overwritten/lost, while the increments are preserved.Consider the following interleaving sequence:1.P2 reads into .
2.P2 is preempted before writing.
3.P1 runs to completion:
- Reads .
- Updates .
- It decrements its local copy: .
- It writes . (P1's update of 120 is overwritten).
- Reads .
- Updates .
1.P1 reads into .
2.P1 is preempted.
3.P2 runs to completion:
- Reads .
- Updates .
- Reads .
- Updates .
- It increments its local copy: .
- It writes .
Thus, the maximum possible value of is:---
3. Calculating
Using the obtained minimum and maximum values:- Minimum value,
- Maximum value,
Can we achieve a higher value than ?
Suppose P1 and P3 both execute their reads when .
1.P1 reads .
2.P3 reads .
3.P2 runs to completion:
- Reads .
- Updates .
- Updates .
- Updates .
1.P1 reads .
2.P2 runs to completion: .
3.P1 writes: .
4.P3 runs to completion: reads , writes .
Let's verify if this sequence is valid:- P1 reads into . [Preempted]
- P2 reads , decrements to , and writes . [Completed]
- P1 resumes, calculates , and writes . [Completed]
- P3 reads , increments to , and writes . [Completed]
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…