title: How to use semaphores correctly
body: <p>I've been posed a problem along the lines of Santa's workshop where numerous things have to happen before presents can be delivered. One such requirement is that eleven elves successfully manufacture 100 presents. My main class looks like this:</p>
  
  <pre><code>public class Main {
  
      public volatile int toyList = 100;
  
      public int getToyList() {
          return toyList;
      }
  
      public void setToyList(int toyList) {
          this.toyList = toyList;
      }
  
      public static void main(String[] args){
          Main main = new Main();
  
          ...
  
          Elf elfOne = new Elf("Jim", main);
          Elf elfTwo = new Elf("John", main);
          Elf elfThree = new Elf("Eamonn", main);
          Elf elfFour = new Elf("Eoin", main);
          Elf elfFive = new Elf("Ronan", main);
          Elf elfSix = new Elf("Seamus", main);
          Elf elfSeven = new Elf("Rebecca", main);
          Elf elfEight = new Elf("Orla", main);
          Elf elfNine = new Elf("Tina", main);
          Elf elfTen = new Elf("Filly", main);
          Elf elfEleven = new Elf("Jess", main);
  
  
          ...
  
          elfOne.start();
          elfTwo.start();
          elfThree.start();
          elfFour.start();
          elfFive.start();
          elfSix.start();
          elfSeven.start();
          elfEight.start();
          elfNine.start();
          elfTen.start();
          elfEleven.start();
  
      }
  </code></pre>
  
  <p>and my Elf class looks like this:</p>
  
  <pre><code>public class Elf extends Thread{
  
      Semaphore semaphore = new Semaphore(11);
      Random rng = new Random();
      String name;
      Main main;
  
      public Elf(String name, Main main){
          this.name = name;
          this.main = main;
      }
  
      public void run(){
          while(true){
                  try {
                      semaphore.acquire();
                      makeToy();
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  } finally {
                      semaphore.release();
                  }
          }
      }
  
      private void makeToy() throws InterruptedException{
          if (main.getToyList() != 0){
              if(rng.nextInt(99) &lt;= 4){ //5% chance to fail
                  System.out.println(name + " failed in making a toy!");
              }else{
                  main.setToyList(main.getToyList() - 1);
                  System.out.println(name + " created a toy! Toys remaining: " + main.getToyList());
              }
          } else {
              wakeSanta();
          }
      }
  
      private void wakeSanta() throws InterruptedException {
  
      }
  
  }
  </code></pre>
  
  <p>A sample output I get is:</p>
  
  <pre><code>...
  Eamonn created a toy! Toys remaining: 6
  Jim created a toy! Toys remaining: 7
  Eoin created a toy! Toys remaining: 8
  Jess created a toy! Toys remaining: 9
  Filly created a toy! Toys remaining: 0
  </code></pre>
  
  <p>The output I'd like to get is that it counts down sequentially with a random Elf from 100 to 0. Is it something as simple as my semaphore acquisition being in the wrong place or am I misunderstanding semaphores altogether?</p>