title: Bakery algorithm (deadlock?)
body: <p><a href="http://en.wikipedia.org/wiki/Lamport%27s_bakery_algorithm" rel="nofollow">http://en.wikipedia.org/wiki/Lamport%27s_bakery_algorithm</a></p>
  
  <p>I have some problems to understand this algorithm. What happens if the current thread and the thread, I am looking at the moment in the for loop are the same?</p>
  
  <p>Threads: 0, 1, 2</p>
  
  <p>Thread 1 takes ticket 1. Thread 2 takes ticket 2. Thread 0 does nothing.</p>
  
  <p>Array = i: 0, 1, 2</p>
  
  <p>Round 1:</p>
  
  <ul>
  <li>Thread 1 (j=0): Array[0] = 0. next.</li>
  <li>Thread 2 (j=0): Array[0] = 0. next.</li>
  </ul>
  
  <p>Round 2:</p>
  
  <ul>
  <li>Thread 1 (j=1): Array[1] = 1. (1,1) > (1,1)</li>
  <li>Thread 2 (j=1): Array[1] = 1. (1,1) > (2,2)</li>
  </ul>
  
  <p>(1,1) > (1,1) wrong.
  (1,1) > (2,2) wrong.</p>
  
  <p>Both threads are waiting...</p>
  
  <p>What's wrong? Is this a deadlock?</p>