Skip to content
Official PYQ · 2019

GATE CS 2019 Q23 — Concurrency and Synchronization

Explain with AI
Consider three concurrent processes P1,P2P_1, P_2 and P3P_3 as shown below, which access a shared variable DD that has been initialized to 100.100. P1P2P3::::::D=D+20D=D−50D=D+10::::::\begin{array}{|c|c|c|} \hline P_1 & P_2 & P_3 \\ \hline : & : & : \\ : & : & : \\ D=D+20 & D=D-50 & D=D+10 \\ : & : & : \\ : & : & : \\ \hline \end{array} The processes are executed on a uniprocessor system running a time-shared operating system. If the minimum and maximum possible values of DD after the three processes have completed execution are XX and YY respectively, then the value of Y−XY-X is ______
View worked solution

Answer: 80

Each assignment statement D=D+kD = D + k is executed at the machine level as three instructions:

  1. Read: Load DD into a local register RiR_i.
  2. Modify: Ri←Ri+kR_i \leftarrow R_i + k.
  3. Write: Store RiR_i back to DD.

To find the minimum and maximum possible final values of DD (initialized to 100100):

1. Minimum Value (XX):

We want the decrement operation of P2P_2 (−50-50) to overwrite the increments of P1P_1 and P3P_3:

  • P2P_2 reads D=100D = 100 (R2=100R_2 = 100).
  • P1P_1 and P3P_3 execute completely in sequence, updating DD to 130130 (100→120→130100 \to 120 \to 130).
  • P2P_2 resumes, decrements its register (R2=50R_2 = 50), and writes D=50D = 50.

Thus, the minimum value is X=50X = 50.

2. Maximum Value (YY):

We want the increment of P3P_3 (+10+10) to overwrite the decrement of P2P_2 (−50-50):

  • P1P_1 executes completely, updating DD to 120120.
  • P3P_3 reads D=120D = 120 (R3=120R_3 = 120).
  • P2P_2 reads D=120D = 120 (R2=120R_2 = 120).
  • P2P_2 decrements and writes D=70D = 70.
  • P3P_3 resumes, increments its register (R3=130R_3 = 130), and writes D=130D = 130.

Thus, the maximum value is Y=130Y = 130.

The required difference is:

Y−X=130−50=80Y - X = 130 - 50 = 80

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Concurrency and Synchronization questions