title: Deadlock in Java code with Semaphore and acquire(int)
body: <p>I have the following Java code:</p>
  
  <pre><code>import java.util.concurrent.*;
  
  class Foo{
      static Semaphore s = new Semaphore(1);
  
      public void fun(final char c, final int r){
          new Thread(new Runnable(){
              public void run(){
                  try{ 
                      s.acquire(r);
                      System.out.println(c+"_"+r);
                      s.release(r+1);
                  } catch(Exception e){ e.printStackTrace(); }
              }
          }).start();
      }
  }
  
  class ths{
      public static void main(String[]args) throws Exception{
          Foo f = new Foo();
          f.fun('B',2);
          f.fun('F',6);
          f.fun('A',1);
          f.fun('C',3);
          f.fun('D',4);
          f.fun('E',5);
      }
  }
  </code></pre>
  
  <p>Ideally, this should print A_1 through F_6 in order and exit, but for some reason that doesn't happen. It usually prints A_1 and B_2 and then it gets stuck.</p>
  
  <p>I can't find anything obviously wrong with my code. Any suggestions?</p>