0

Process X code:

I don't understand how bounded waiting is achieved here.

do {
     while (turn != x);

     // critical section code goes here.

     turn = y;

     // remainder section code goes here.
} while(1);
CallumDA
  • 12,025
  • 6
  • 30
  • 52

2 Answers2

0

If you are preparing for OS examination,according to "Operating System Concepts ",the answer is: "It does maintain bounded waiting but doesn't maintain progress."

If both Pi and Pj want to enter critical section and turn = i.Then Pi enter first and Pj wait for it .After Pi exit,even Pi want to enter critical section again,Pj can still can enter critical section before Pi enter again.So Pj at most wait one turn to enter CS.

It doesn't maintain progress .Because if Pj want to enter CS and turn=i.It have to rely on Pi,which is probably doesn't want to enter CS right now,to set turn=j.

王智寬
  • 415
  • 1
  • 5
  • 17
-1

This code does not maintain bounded waiting.

Here's the scenario, where Process X is made to wait indefinitely.

Suppose Process X enters Critical Section and leaves it. The variable turn will be set to y. Now for Process X to be able to again enter Critical Section, variable turn, must be set to x, which cannot happen as long as Process Y enters the Critical Section.

So, only if the two processes X and Y, alternatively enter Critical Section, only then bounded waiting is satisfied, otherwise, not.

Sumeet
  • 8,086
  • 3
  • 25
  • 45
  • IMHO, The bounded waiting is not about for processes to enter critical section alternatively. — https://stackoverflow.com/a/33409854/9304999 – rosshjb Apr 13 '22 at 05:39