2,575 views
5 votes
5 votes
// a software solution for critical section problem

bool flag[2];
int turn;

void process(int id) {
  while(true) {
    flag[id] = true;
    while(turn != id) {
      while(flag[1-id]);
      turn = id;
    }

    < Critical Section >

    flag[id] = false;
  }
}

int main(int argc, char const *argv[]) {
  
  flag[2]={0,0};
  turn = 0;
  
  parbegin
    process(0);
    process(1);
  parend	
  
  return 0;
}

Which of the following is false ?

  1. Mutual exclusion is satisfied.
  2. Progress is satisfied.
  3. Bounded waiting is satisfied.
  4. None.

3 Answers

5 votes
5 votes

i think its option B. here bounded waiting is not satisfied.
initially turn =0
process 0 can enter into CS any number of times even when process 1 made its flag as 1.
 

while(true) {
 1.   flag[id] = true;
 2.  while(turn != id) {
 3.     while(flag[1-id]);
 4.    turn = id;
    }
 5.   < Critical Section >
 6.   flag[id] = false;
  }
suppose process0 came, 
p0 : 1 (p0 made its flag as 1)
p1  : 1 (p1 made its flag as 1) 
p0 : 2,5,6 (turn!=0 is false so, it doesnt care if p1 is intrested in CS or not, without seeing the flag of p1, it executes CS) 
now again p0 tries to enter 
p0: 1,2,5,6 this continues..
p0 can enter CS any number of times
so bounded waiting is not satisfied
1 votes
1 votes

As per Dekker and Peterson , we can work with both with flag[] and turn both variables.

Now, 2 process wants to enter critical section. Initially turn=0.

Now, say process[0] wants to enter critical section first. It makes flag value=0. But it is only can go in critical section when turn=1 and flag=1. So ,flag[0] and flag[1] both are active at the same time. Means both process can enter critical section at the same time.

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

Now, here ME not not satisfied, as both process are active in single turn, means both can enter C.S. at the same time.

flag[id] = true;//here flag[0] can enter C.S.
while(turn != id) {
      while(flag[1-id]);//here flg[1] also actively go in C.S.
      turn = id;

Now,  it is not a strict alteration. And flag is not a bound for a process to enter into C.S. next. So, Progress will satisfy.

Bounded waiting- Here the process[0] and process[1] has no bound for entering C.S. next. Both are active at the same time. So, Bounded waiting not satisfied here.

So, option 1) and 3) are false

1 votes
1 votes

Answer is option C.

Actually bounded waiting is not satisfied. Process P0 or P1  can execute in the critical sections  with out any bound.

Let us assume process P0 is executing in its critical section. and process P1 is waiting in the while loop While (flag[1-id]).After completing the execution in the critical section,Po  can access the critical section for any number of times REPEATEDLY without letting process P1 to access the CS.   

Related questions

0 votes
0 votes
0 answers
2
Raj Singh 1 asked Jan 1, 2019
1,433 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...