CS706 Fall 2009 Homework #2 Due: Tuesday, September 29. You may work on this homework in groups. 1. Exercise 3-6 2. Exercise 3-9 3. Exercise 3-11 4. Exercise 3-7 You must have three separate and different solutions for parts (a), (b), and (c). Note: For part (c): - you probably want to keep track of the number of waiting men and women. - once one man enters the bathroom, he can let other waiting men enter too; same for when a woman enters the bathroom. Test your solutions to parts (a), (b), and (c) by implementing them as Java programs with multiple man/woman threads. I created a template for you in file UnisexBathroom.java. Complete this code by completing class BathroomController. You need to declare any variables you need and complete methods manEnter, manExit, womanEnter, and womanExit. Java classes binarySemaphore and countingSemaphore are in the Modern Multithreading (MM) library on the website for the textbook: http://cs.gmu.edu/~rcarver/ModernMultithreading/LangLibTools.htm I recommend downloading the Java JAR version in ModernMultithreadingJavaJar.zip. Use operations V and P, but *not* VP. (There is no need to use VP.) You should have counters "numMen" and "numWomen" in your program, which count the number of men and women, respectively, who have entered the bathroom. At the point where men actually enter the bathroom, add the check: if (numWomen>0) System.out.println("Error: concurrent access"); This detects when men and women are both in the bathroom. Do the same check with numMen when women enter the bathroom. Perhaps this will help you detect errors. After your program appears to be running correctly, use the RTDriver to run your program in reachability testing mode with deadlock detection on. Assuming that you are using the jar file: Windows: java -classpath .;ModernMultithreading.jar -Dmode=rt -DdeadlockDetection=on -DVPReduction=on RTDriver UnisexBathroom Unix: java -classpath .:ModernMultithreading.jar -Dmode=rt -DdeadlockDetection=on -DVPReduction=on RTDriver UnisexBathroom (Here I am assuming the jar file is in the same directory as your UnisexBathroom.java file.) If you are using the source code files instead: java -Dmode=rt -DdeadlockDetection=on -DVPReduction=on RTDriver UnisexBathroom (Here I am assuming the source code files are in the same directory as your UnisexBathroom.java file.) You may want to comment out any calls to Thread.sleep() and any output statements before you run in rt mode. The file RTDriver is in the library. Reachability testing will go a lot faster if you use the "symmetry reduction": Windows: java -classpath .;ModernMultithreading.jar -Dmode=rt -DdeadlockDetection=on -DVPReduction=on -DsymmetryReduction=on RTDriver UnisexBathroom Unix: java -classpath .:ModernMultithreading.jar -Dmode=rt -DdeadlockDetection=on -DVPReduction=on -DsymmetryReduction=on RTDriver UnisexBathroom or if you are using the source code files instead of the jar file: java -Dmode=rt -DdeadlockDetection=on -DVPReduction=on -DsymmetryReduction=on RTDriver UnisexBathroom Make sure you create the symmetry.txt file as explained in UserManual.pdf. For example, my symmetry.txt file for part (a) contained the following 2 lines: 2 3 4 5 6 7 The first line contains the IDs of the men (4, 5, and 6) and the second line contains the IDs of the women. Your symmetry.txt file may be different, depending on how many semaphores you defined in your solution. To capture the IDS that are being used: 1. Run reachability testing for a few seconds *without* symmetry reduction; this will create a file named ThreadID.txt, which records the IDs used for the men and women threads. 2. Use the IDs in ThreadID.txt to create your symmmetry.txt file. Note: You may need a different symmetry.txt file for parts (a), (b), and (c). Submit your source code and a "statement of correctness" in which you either state that your program is (believed to be) correct or you describe any problems that you are aware of. Also, state the results of reachability testing (i.e., the number of sequences that were exercised and whether any deadlocks were detected). Note: If you downloaded the library files, you can put your UnisexBathroom.java file in the same directory as the library files and compile them all using: javac *.java If you are using the jar file, you can put your UnisexBathroom.java file in the same directory as the jar file and compile it using: Windows: javac -classpath .;ModernMultithreading.jar UnisexBathroom.java Unix: javac -classpath .:ModernMultithreading.jar UnisexBathroom.java There are other ways to do it, but this is a simple way that works. If you put your UnisexBathroom.java file and the library/jar files in different directories, you'll need to set your classpath so all the files will be found. Note: the Zip file for the library and for the jar file has a UserManual file in it. You don't need to read it all now, but take a look when you get a chance. There are example program directories in the Zip file also.