GATE - 2019 | Consider three concurrent processes P1, P2 and P3 as shown below

Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100.
Posted on 02-02-2022

GATE - 2019 [Operating System]

Question:

Consider three concurrent processes P1, P2, and P3 as shown below, which access a shared variable D that has been initialized to 100.

Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100.

The process 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 _______.

Solution 1:

Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100.

P2 reads D=100, preempted.
P1 executes D=D+20, D=120.
P3 executes D=D+10, D=130.
Now, P2 has D=100, executes
D = D-50 = 100-50 = 50
P2 writes D=50 final value. This is minimum.
Next,
P2 reads D=100, executes D = D-50, before that assume P1 & P3 has read D=100.
P2 makes D=50 & writes it.
P1 executes (D=100), D=D+20 & P3 executes D=D+10 gives maximum value D=130.
So, Y - X = 130 - 50 =80.

-------------------------------------------------------------------------

Solution 2:

Minimum value (X) of D will possible when,

  1. P2 reads D=100, preempted.
  2. P1 executes D=D+20, D=120.
  3. P3 executes D=D+10, D=130.
  4. Now, P2 has D=100, executes, D = D-50 = 100-50 = 50. P2 writes D=50 final value.

So, minimum value (X) of D is 50.

Maximum value (Y) of D will possible when,

  1. P1 reads D=100, preempted.
  2. P2 reads D=100, executes, D = D-50 = 100-50 = 50.
  3. Now, P1 executes, D = D+20 = 100+20 = 120.
  4. And now, P3 reads D=120, executes D=D+10, D=130. P3 writes D=130 final value.

So, maximum value (Y) of D is 130.

Therefore,

= Y - X
= 130 - 50
= 80 
Thank You
  1. GATE - 2019 | Consider three concurrent processes P1, P2 and P3 as shown below
  2. GATE - 2019 | The following C program is executed on a Unix/Linux system:
  3. GATE - 2019 | Assume that in a certain computer, the virtual addresses are 64 bits long
  4. GATE - 2019 | Consider the following four processes with arrival times (in milliseconds)

Download App for Free PDF Download

GovtVacancy.Net Android App: Download

government vacancy govt job sarkari naukri android application google play store https://play.google.com/store/apps/details?id=xyz.appmaker.juptmh