In this simulation, there is one Santa Claus thread, 20 reindeer threads, and 11 elf threads. In the beginning, the reindeer threads are in the barn and the elf threads are in the toy factory. Santa Claus waits in his shop up at the North Pole, and can only be unblocked by either
As in all our programming assignments, use command line arguments to set the simulation parameters.
Remember that Java monitors are `signal and continue' so be sure to think about the ramifications of this as you design your monitor, in particular ``barging''. No semaphores and no busy waiting allowed. Do not use nap() within a synchronized monitor method.
For the purposes of this assignment you may assume that each notify() awakens the thread that has been waiting the longest. But it is unpredictable when that thread will get back into the monitor. It is possible for other threads that have called a monitor synchronized method to ``barge'' in ahead of it. Also, notifyAll() awakens all the waiting threads and it is unpredictable which thread will get back into the monitor first and whether another thread will ``barge'' in ahead of it.
Here is one way to approach a monitor programming assignment. Think of the monitor as maintaining the state of the system in integer and boolean data fields and the synchronized methods as making atomic changes to the state of the system. If a thread enters the monitor and needs a resource that is currently unavailable or needs to synchronize with another thread, then
while (condition) wait();Any time a thread changes a variable that may affect the condition some other thread is waiting on, do a notifyAll() before exiting the method.
Animate your program using XtangoAnimator.java. First do the base assignment as specified above and turn it in. Then do an animation of it as a separate program.