CSE 120 Spring 2002 Homework 1

Solutions

Problem 1

Some simple machine organization questions:
  1. Briefly describe the differences between traps and interrupts.

  2. The terms are used in different ways. One difference is that a trap occurs synchronously with the intstruction stream while an interrupt occurs asynchronously. Thus, a divide by zero exception would be a trap, while the completion of an I/O request would be an interrupt.
     
  3. Many architectures rank interrupts in terms of priorities. What do these priorites represent? Why is this a useful thing to do?

  4. The priorities have to do with masking: when a handler for a priority at some level is executing, only priorities at a higher level can be serviced (the rest remain pending). Having priorities means that interrupt routines need not be re-entrant, and it allows for events with a shorter time to respond to be handled even when lower priority events occur.

Problem 2

Consider the following proposed solution of the mutual exclusion problem. I've added line numbers in black.
    int in0 = 0, in1 = 0;
    cobegin
    while (1) {
      in0 = 1;            1
      while (in1) {       2
        in0 = 0;          3
        while (in1) ;     4
        in0 = 1;          5
        }
      critical section
      in0 = 0;            6
      }
    ||
    while (1) {
      in1 = 1;            7
      while (in0) {       8
        in1 = 0;          9
        while (in0) ;    10
        in1 = 1;         11
        }
      critical section
      in1 = 0;           12
      }
    coend
  1. Does the solution satisfy the safety property of the mutual exclusion problem? If so, then give an informal argument saying why. If not, then give an adversary schedule that violates safety.

  2. It does. Suppose, without loss of generality, thatn process 0 enters its critical section. When it entered, in0 was true and in1 was false. If in1 is false, then process 1 is at 7, 10, or 11. In all of these cases, process 1 will not enter its critical section as long as in0 is true, whose value process 0 does not change until line 6 after it leaves its critical section.
     
  3. Does the solution satisfy the liveness property of the mutual exclusion problem? If so, then give an informal argument saying why. If not, then give an adversary schedule that violates liveness.

  4. It does not: *1; 2; 3; 7; 8; 9; 4; 10; 5; 11)* is a valid infinite behavior in which each process takes a step infinitely often and in which neither enters the critical section.

Problem 3

Consider an elevator, such as one of those in AP&M.
  1. Define a state of this system as a set of variables.

  2. The motion of the elevator: {up, down, stopped}
    The state of the doors: {open, shut}
    The weight of the cargo in the evevator
    The location of the elevator (including between floors).
    The floors at which the call button has been pressed (and not yet reset).
     
  3. Give two safety properties of this system.

  4. The doors are closed when the elevator is moving.
    The elevator moves only if the weight of cargo does not exceed a given value.
     
  5. Give two liveness properties of this system.

  6. When the elevator is not moving and the elevator is at a floor then the doors will eventually open.
    If f is a floor at which the call button is pressed, then eventually the elevator will be at f and not moving.

last edited 6 May 2002 by kam