0

For the following, I'd like to know what would happen in the case below:

//global declarations
Boolean in1=false, in2=false;
Process P1::
while(1){
  //entry protocol
  while(in2){
    in1=true;
  }
  //--critical section --
  //exit protocol
  in1=false;
}
Process P2::
while(1){
  //entry protocol
  in2=true;
  while(in1){
    in2=true;
  }
  //--critical section --
  //exit protocol
  in1=false;
}

Just a bit stumped with this at the moment, because I think it just lacks mutual exclusion - but just wanted to make sure!

Cloud
  • 18,753
  • 15
  • 79
  • 153
m1dday
  • 1

1 Answers1

0

The pseudocode doesn't have proper mutual exclusion. Consider P1 executing first:

  • Since initially in2=false, P1 gets over its entry protocol and enters the critical section.
  • If P2 executes then, since still in1=false, P2 gets over its entry protocol and enters the critical section, too, thus no mutual exclusion.

Regarding indefinite postponement:

  • After P2 executed in2=true, in2 is never again set to false.
  • So, P1 cannot get over its entry protocol's while(in2) loop and is postponed in(de)finitely.
Armali
  • 18,255
  • 14
  • 57
  • 171