Assignment 13, not due

Part of the homework for CS:2820, Spring 2019
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

This assignment is not to be turned it. It consists of study questions to help you prepare for the final exam.

  1. Background: Get and install Logicsim.shar in a new directory. Call the directory Logicsim. Use the make tests command to compile and test it. It should work. The test script here is the same one that was distributed with the posted solution to MP5, and the program should behave the same as MP5.

    The difference is, Logicsim has a different simulation framework; Yet another framework, different from any that we have discussed in class.

    a) Find some examples of calls to Simulation.schedule() in Logicsim and compare them with the corresponding versions in MP5. How do they differ? (0.0 points)

    b) How does an event service routine in Logicsim learn its simulated time? How is this different from the way the corresponding code in MP5 learned about its time. (0.0 points)

    c) When do event service routines in Logicsim actually need to know their times? Is this something most event service routines needs, or only some? why? (0.0 points)

    d) Simulation.schedule() still has two parameters, but both have been changed from the original version. Look at the float parameter. What values of this parameter would be unquestionably wrong? What would the error values cause, in the context of the simulated system? Should the code perform some kind of sanity check to assure that such wrong values are not allowed? (You might want to compare with the sanity check in Simulation.Semaphore().) (0.0 points)

  2. Background: Class Simulation in Logicsim contains a new static inner class, Semaphore, based on the discussion from the lectures on April 26. This is not used anywhere in the code of Logicsim; that code was merely used to distribute it to you.

    If you have a series of event-service routines, where one of them schedules the next, which schedules the next, that sequence is a logical process. Consider two logical processes, one made of the three routines a, b and c and the other made of x, y and z. If there were no synchronization constraints, a could simply schedule b, b could simply schedule c, x could simply schedule y, and y could simply schedule z.

    Now, suppose we want z to happen after both y and b. We can solve this synchronization problem using an object s of class Simulation.semaphore().

    For the sake of this problem, assume that the simulated time intervals between successive events in each process is exactly 1.0 and assume that z must happen exactly 1.0 after y or b, whichever happened last. Also, assume that the event service routines have no parameters, and that each of these events happens exactly once.

    a) How would the code for event service routine a end to schedule b? (0.0 points)

    b) How would you declare and initialize s to solve the synchronization problem here? (0.0 points)

    c) How would the code for event service routine b end to schedule c and enable z? (0.0 points)

    d) How would the code for event service routine y end to schedule z but only when b has already been completed. (0.0 points)

  3. Background: Here is code for an uncontrolled intersection that could be added to our road-network simulator. It uses the new simulation framework introduced in problem 1, and it uses Simulation.Semaphore.
    final class Uncontrolled extends Intersection {
        private Simulation.Semaphore occupied = ...
    
        public StopLight( Scanner sc ) {
            super( sc );
            ScanSupport.finishLine( sc, () -> this + " followed by junk" );
        }
    
        // simulation methods
    
        public void enter( int source ) {
            occupied.wait( delay, () -> exit() );
        }
    
        private void exit() {
            pickRoad().enter();
            occupied.signal();
        }
    }
    

    a) If the enter method above had just done simulation.schedule(delay,()->exit()) instead of using the semaphore, how would the behavior differ? (0.0 points)

    b) What determines the number of cars that can simultaneously coexist in the intersection? (0.0 points)

    c) How should occupied be initialized if we want to enforce the usual conservative rule that only one car can occupy any intersection at one time. (0.0 points)

    d) If a car arrives at the intersection and it is full of other cars, it is put on some queue. Where is the queue hiding in this code? (0.0 points)