title: Does Peterson's algorithm satisfy starvation?
body: <p>I've been searching information on <a href="http://en.wikipedia.org/wiki/Peterson%27s_algorithm" rel="noreferrer">Peterson's algorithm</a> but have come across references stating it does not satisfy starvation but only deadlock. Is this true? and if so can someone elaborate on why it does not? </p>
  
  <p>Peterson's algorithm:</p>
  
  <pre><code>flag[0]   = 0;
  flag[1]   = 0;
  turn;
  
  P0: flag[0] = 1;                                       
      turn = 1;                                               
      while (flag[1] == 1 &amp;&amp; turn == 1)                        
      {                                                       
             // busy wait                                             
      }                                                                                      
      // critical section                                     
         ...                                                     
      // end of critical section                              
      flag[0] = 0;   
  
  P1: flag[1] = 1;                                       
      turn = 0;                                               
      while (flag[0] == 1 &amp;&amp; turn == 0)                        
      {                                                       
             // busy wait                                             
      }                                                                                      
      // critical section                                     
         ...                                                     
      // end of critical section                              
      flag[1] = 0;
  </code></pre>
  
  <p>The algorithm uses two variables, flag and turn. A flag value of 1 indicates that the process wants to enter the critical section. The variable turn holds the ID of the process whose turn it is. Entrance to the critical section is granted for process P0 if P1 does not want to enter its critical section or if P1 has given priority to P0 by setting turn to 0.</p>