title: Baby birds concourrent programming
body: <p>I have a problem of concourrent programming that I can't get solved by myself. I have to use Java Monitors to solve it.</p>
  
  <p>The problem is the following:</p>
  
  <p>Deep in the Amazon jungle lives a species of birds called Cooeecooee. These remarkable birds have an unusual behavior in raising their chicks:</p>
  
  <ol>
  <li>Parents alternate between hunting, dropping food in the nest, and resting.</li>
  <li>The parents feed the chicks by depositing a certain amount (or portions) of food in the nest.</li>
  <li>To teach the chicks that they must eat all food that is available, parents never deposit food in the nest until all previous food has been consumed. If the nest is not empty, they wait until nest is empty before adding food.</li>
  <li>Note that the nest can contain at most a capacity C of food (strangely enough, parents never return with more than C portions of food from a hunt. Observations show that the parents will feed themselves with the extra food in such a manner that at most C portions of food will ever be deposited).</li>
  </ol>
  
  <p>Meanwhile, the chicks do all what babies do:</p>
  
  <ol>
  <li>Sleep</li>
  <li>Eat (1 portion of food a time)</li>
  <li>Produce guano</li>
  </ol>
  
  <p>The program simulates life of these birds, creating two parent processes, and several chick processes.</p>
  
  <p>The behavior of chicks and parents thus resembles the situation described by the following pseudo-code:</p>
  
  <pre><code>process Chicks(many of them) {
      repeat {
          sleep();
          get_food();
          eat();
          digest_and_poop();
      }
  }
  
  process Parents(just two) {
      repeat {
          hunt();
          deposit_food();
          rest();
      }
  }
  </code></pre>
  
  <p>The simulation will be invoked with the following parameters:</p>
  
  <ul>
  <li>chicks: is the number of chick processes</li>
  <li>baby_iter: is the number of iterations a baby chick does before it reaches adulthood</li>
  <li>max_food_size: is the maximum portion size a parent brings back from a hunt (same as the capacity of the nest, as it turns out)</li>
  <li>hunting_success_rate: represents the success rate a parent has when hunting. A rate fo 50% means that a parent returns with no food.</li>
  </ul>
  
  <p>Synchronization is done by monitors.</p>
  
  <p>Can somebody help me? Because I've resolved similar problems with Semaphores but I can't figure out how Monitors works on Java.</p>
  
  <p>Thank you.</p>