GATE - 2016 | OS | Consider the following proposed solution for the critical section problem.

GATE - 2016 | OS | Consider the following proposed solution for the critical section problem.
Posted on 09-02-2022

GATE - 2016 [Operating System]

Question:

Consider the following proposed solution for the critical section problem. There are n processes: P0...P(n-1). In the code, function pmax returns an integer not smaller than any of its arguments. For all i, t[i] is initialized to zero.

Code for Pi:

 

do {

 

      c[i]=1; t[i] = pmax(t[0],...,t[n-1])+1; c[i]=0;

      for every j ≠ i in {0,...,n-1} {

           while (c[j]);

           while (t[j] != 0 && t[j]<=t[i]);

      }

      Critical Section;

      t[i]=0;

      Remainder Section;

} while (true);

Which one of the following is TRUE about the above solution?

A

At most one process can be in the critical section at any time

B

The bounded wait condition is satisfied

C

The progress condition is satisfied

D

It cannot cause a deadlock

    

Solution:

Option (A) is Correct.

We will check the four options one by one.
Based on the above code option B, C and D are not satisfied.
We can see that while (t[j] != 0 && t[j] <= t[i]);
because of this condition deadlock is possible when t[j] = = t[i].
Because Progress == no deadlock as no one process is able to make progress by stopping other process.
Bounded waiting is also not satisfied.
In this case both deadlock and bounded waiting are to be arising from the same reason as if t[j] = = t[i] is possible then starvation is possible means infinite waiting.
Mutual exclusion is satisfied.
All other processes j started before i must have value of t[j]) < t[i] as function pMax() return a integer not smaller than any of its arguments.
So if anyone out of the processes j have positive value will be executing in its critical section as long as the condition t[j] > 0 && t[j] <= t[i] within while will persist.
And when this j process comes out of its critical section, it sets t[j] = 0; and the next process will be selected in for loop.
So, when i process reaches to its critical section none of the processes j which started earlier before process i is in its critical section.
This ensures that only one process is executing its critical section at a time.
So, A is the answer.

 

Thank You

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