This is Exercise 4.7 of the text. Do not worry (yet) about starvation, that is, only do the first part. A big hint: modify the readers and writers database program so that multiple writers can write concurrently as long as no readers are reading the database, i.e., make writers act like readers.
As in all our programming assignments, use command line arguments to set the simulation parameters, such as the number of males, females, baboons of each type, maximum nap time outside the bathroom, maximum nap time inside the bathroom, etc.
To find the cause of deadlock, remember that a thread blocks when doing a P() on a semaphore with zero value. To find where each thread is blocked in the deadlock, put a System.out.println() before each P() and a System.out.println() after each P() so you can see how far each thread is getting before blocking and see if it is getting past a P().
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.