title: How does Test and Set Instruction provide Bounded Waiting in below code?
body: <p>In the below code how is bounded waiting condition satisfied ,I am unable to get the usage of these statements ,why have they applied the condition j!=i and j=(j+1)%n and then the condition mentioned inside if clause using (j==i),please clarify this ,according to me it should only check for waiting[j] , so as to confirm if any other process is waiting for lock or not ,I am unable to get the idea of working of this algorithm ,please explain it .</p>
  
  <pre><code>while ((j != i) &amp;&amp; !waiting[j]) 
              j = (j + 1) % n; 
          if (j == i) 
              lock = false; 
  
  do {
      waiting[i] = true;
      while (waiting[i] &amp;&amp; test_and_set(&amp;lock)) ;
      waiting[i] = false;
  
      /* critical section */
  
      j = (i + 1) % n;
      while ((j != i) &amp;&amp; !waiting[j]) 
          j = (j + 1) % n; 
      if (j == i) 
          lock = false; 
      else
          waiting[j] = false;
  
      /* remainder section */
  } while (true);
  </code></pre>