Question

The Operating System Concepts 6th edition present one trival algorithm to implementate ciritical section.

do{
  while (turn != i);
    critical section
  trun = j;
    remainder section
} while(1);

Note,Pi is the process with identifier i,Pj is the process with identifier j.To simlify the question,the book limit the i,j to 0 and 1,the two processes constriant enviroment.

Question1 is,dose this algorithm voilate the Progress requirement which is one of the three requirements to ciritical section solution?

In my opinion,when Pi is in its remainder section,it cannot participate in the decision on whether Pj can enter the critical section.Then it is bound to the requirement.

Or my understanding of progress requirement is totally wrong.So because if Pi retired from the remainder section,It could not get into the cirtical section immediate,this alg violate the rule.

Question2,

If turn == 0 and P1 is ready to enter itscritical section,P1 cannot do so,even thought P0 may be in its remainder section

Whats the meaning of this statement?As far as I could think,I could not understand why turn == 0 and p0 be in its remainder section could be exist concurrently...

So is this statement wrong?

Was it helpful?

Solution

Suppose that turn = 0 initially. P0 does its critical section and sets turn = 1. Now, P1 must execute its critical section before P0 may execute its one again. But just because both threads have a critical section doesn't mean that they're going to want to alternate their use of it in this way — in fact, P1 may never take its turn. (And in the general case, you can't determine this at compile time.)

So basically the problem is that the threads are forced to alternate their turns, even if one of them actually doesn't want to enter its critical section for an indefinitely long time.

By the way, your answer to Question 1 is correct. The algorithm doesn't fail the Progress condition, it fails the Bounded Waiting condition.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top