1,131 views
0 votes
0 votes

repeat 

     flag[i]=true;

     turn =j;

     while(flag[j] and turn=j ) do no op;

      critical section;

      flag[i]= false;

       remainder section;

 until false;

 

Above algorithm is the correct soln of the critical section problem which satisfies all the three codition-1.>mutual exclusion 2.>progress 3.>bounded waiting

my question is how this algorithm satisfies bounded waiting ??let say both the process pi and pj want to enter its critical section then they will turn flag[i] and flag[j] to 1 then pi while change the value of turn to j and and pj to i but turn can contain only one value so any one of the process will enter its cs let say it is pi.later the process pi on completion again want to enter its cs then is it will be executed indefinetly and pj will never be executed if this phenomenon is repeated  .so,please tell me where i m wrong .

2 Answers

0 votes
0 votes

yes. you are right but that is starvation .Notice here Pj  is  sure that it is bounded to enter cs by only one process. there will not be infinite number of process before it that could enter cs.hence bounded waiting is satisfied as only one process could enter cs before it i.e P and the number of bound is known or limited.

since you felt about  starvation then if you notice ,it  is even prone to deadlock if both process are preempted after each of them  executes till "turn = j "  later when any of them come to WHILE .. it would be TRUE always and hence they continue doing no operation waiting indefinitely for an action which could be done by one another  . BUT, anyway we are interested only to handle critical section here.

0 votes
0 votes
what u got wrong here is again when the p1 come after executing it will change the turn varaible to himself and then the older process while condition will break so after one another will go in . so aftre every 1 step second is getting a change to enter so .

Related questions

0 votes
0 votes
0 answers
1
Raj Singh 1 asked Jan 1, 2019
1,430 views
Many problems on gateoverflow asks whether the given code satisfies progress requirement of the solution for the critical section problem. Most of these code contain mult...
0 votes
0 votes
0 answers
2