GATE 2019 CS – Question 33
Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100.
| P1 | P2 | P3 |
|---|---|---|
| D = D + 20 | D = D − 50 | D = D + 10 |
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 ________.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 80
Explanation
Each update is a read-modify-write that may be interleaved. The lowest result happens when P2's write lands last having read 100: $X=100-50=50$. The highest happens when P1 and P3 both complete and P2's update is lost: $Y=100+20+10=130$. So $Y-X=80$.