(Last Revision 11/20/97) (11/11/97 -- changed rules for spawning threads.) (11/20/97 -- correction to the progress condition) DUE Monday, November 24 Robot Problem -- Phase 2. There is a long hall for robots to use to get from one building to another. It runs north-south. Robots can walk from one end of the hall to the other, but the hall is only wide enough for one robot. There is not enough room for robots to pass each other in the hall. Also robots cannot back up or jump over one another. MUTUAL EXCLUSION REQUIREMENTS: Robots must never be allowed to get into the hall facing in opposite directions, else they will crash or deadlock. Because it is more efficient, we want to allow many robots to be traveling at the same time in the same direction in the hall. However, we must make sure that none of them catches up and collides with another robot. As an aid to collision avoidance, the hall is divided into 16 cells. At most one robot is allowed to occupy a cell at any given time. Each cell is protected by a semaphore. THE PROGRAM AND THE PROTOCOL: You will write a C program for the NeXT's that spawns 25 robot threads with calls to cthread_fork(). The mother will randomly assign each robot either to walk north-south across the hall, or south-north. The robots will repeatedly walk through the hall, in their assigned direction. (See phase-02-shell.c). You will devise a protocol by which the robots, mutually and symmetrically carrying out the protocol, are guaranteed to satisfy the mutual exclusion requirements described above and the progress requirements described below. You will implement the protocol in your C program. You may write the program by expanding the contents of file: phase-02-shell.c. PROGRESS REQUIREMENTS: Whenever there are no robots currently traveling south in the hallway, all robots that want to enter and go north through the hallway are eligible to do so. Conversely, whenever there are no robots currently traveling north in the hallway, all robots that want to enter and go south through the hallway are eligible to do so. To paraphrase the textbook definition of progress: Only the robots that are 1) eligible to enter and wish to enter the hallway and 2) the robots that are exiting the hallway can participate in the decision of which will robot will enter next, and this selection cannot be postponed indefinitely. Note: The progress requirement implies, for one thing, that no thread may take on the role of a "coordinator" of the other threads. SYNCHRONIZATION TOOLS: For technical reasons that I will explain in class, your program must use a "mutex_t" lock variable (a tool made available in the C threads package) to lock and unlock standard output for writing messages. Other than that, one exception, you must implement all your program's thread synchronization by using the sim_semaphore data types that I have implemented for your use in the files sem.h and sem.c. These sim_semaphore's behave exactly like the "counting semaphores" described on pp. 177-178 of Silberschatz and Galvin.