This problem demonstrates the use of semaphores to coordinate three types of processes. Santa Claus sleeps in his shop at the North Pole and can only be woken by either:
To allow Santa to get some sleep, the elves can only wake him when three of them are having problems. When three elves are having their problems solved, any other elves wishing to visit Santa must wait for those elves to return. It is assumed that the reindeer do not want to leave the tropics, and therefore stay there until the last possible moment they only return in December. The last reindeer to arrive must get Santa while the others wait in a warming hut before being harnessed to the sleigh.
The objective of this homework is for you to implement this problem as a multithreaded Java using the Java synchronization primitives. Note that implementing this problem requires you to deploy a number of different techniques.
As this is a relatively complex problem, I have decomposed it in a number of steps. You need to submit solutions to Steps 14. Normally, the solution for a step is the starting point for the next step.
Download the SantaProject.zip file from the webpage. Compile and run (the main function is in package org.santa.step0 and is called Main). Easiest way to do this, is to just use the unpacked code as an Eclipse project. Study the code and the output. Notice that in many places in to the code there are FIXME comments which give an idea of what is supposed to go there.
Also note that, for the time being, there are no semaphores or other synchronization primitives in the code.
Create the package org.santa.step1 and copy over the files from step0. Adjust the package names. For the successive steps, you will need to create the corresponding packages step1, step2, step3 etc.
Observe that the threads corresponding to Santa, the reindeer and the elves never terminate. Implement a way to terminate these threads at day 370 using deferred termination (i.e. do not kill the threads explicitly).
Starting from step 1, create a version where:
Starting from step 2, create a version where
Now, notice that Step 3 still did not use any synchronization primitives even when in TROUBLE or at Santas door, the elf threads are spinning. Using semaphores, change the code from Step 3 in such a way that the threads of the Elves are in a wait() state when they are in the TROUBLE mode.
Note: that in Java Semaphores are in the class java.util.concurrent.Semaphore
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Semaphore.html
Now, bring in the reindeers, and implement the code necessary such that: