I really think there is a possibility that infinite or too long while loop would happen.

but my friend once thought that this would work well.

What is right answer??

//sharedVars
t1Enter = true;
t2Enter = true;

//program1
void main()
{
  while (!done) {
    t1Enter = true;
    while (t2Enter) {
      t1Enter = false;
      sleep(10);
      t1Enter = true;
    }
  }
  // critical section

  t1Enter = false;

  // remainder section

//program2
void main()
{
  while (!done) {
    t2Enter = true;
    while (t1Enter) {
      t2Enter = false;
      sleep(10);
      t2Enter = true;
    }
  }
  // critical section

  t2Enter = false;

  // remainder section

0 Answers