Program 4.3 uses semaphores to synchronize three threads so they print out the letters `A', `B', and `C' according to certain rules. Your task in this programming assignment is to synchronize four threads so they print out the letters `W', `X', `Y', and `Z' according to the following rules.
Use binary and counting semaphores for synchronization, as appropriate.
The input data consists of five integer (int) numbers: w, x, y, z, and runtime. You must parse these five numbers from the command line using the GetOpt class (Library Class 2.1). The command line has the form
The numbers w, x, y, and z control the napping time of the four threads printing the corresponding letter, as follows.
class Pw extends ... implements Runnable { public void run () { while (true) { int napping = 1+(int)random(1000*w); // w is in seconds nap(napping); ... // synchronization to follow the rules System.out.print("W"); System.out.flush(); ... // synchronization to follow the rules } } }Before each time a thread prints a letter (according to the rules), it naps for a random number of milliseconds generated from its command line argument (in seconds) or its default value. The number runtime controls how long the whole program runs, i.e., there is a nap(1000*runtime) in the main method.
Animate your program using XtangoAnimator.