Homework 1

CS 318

50 points, due Feb. 16, 1998

  1. (10 pts.) Consider a single processor timesharing system which supports a large number of interactive users. Each time a process gets the processor, the interrupt timer is set to interrupt after the quantum expires. Assume that each process has the same quantum.

    1. What would be the effect of setting the quantum at a very large value, say 10 minutes? What sort of process behavior(s) would preclude this effect?

    2. What would be the effect if the quantum were set to a very small value, say a few processor cycles (machine instructions)?

    3. Obviously, an appropriate quantum must be between the values previously mentioned. If you could vary the quantum, how would you determine when you had chosen the ``right'' value? What factors make this value right from the user's standpoint? What factors make it right from the system's standpoint?

  2. (10 pts.) In Unix, a signal is an abstraction of an interrupt. Non-privileged users are permitted to install their own signal handlers. Recall that interrupt handlers are run in supervisor mode.
    1. Explain why it would be a very bad idea to permit a user's signal handler to run in supervisor mode.

    2. Assuming that the mechanism used to invoke a signal handler places the CPU in supervisor mode, suggest a way (by writing pseudo-code) to safely run user's signal handlers. (Hint: assume that the CPU has a UserMode machine instruction which places the machine in user mode.)

  3. (15 pts.) An alternative to the TAS instruction is the FAI (Fetch And Increment) instruction. Here are its semantics:
    int FAI(int& val)
    {
       return val++;   // Performed atomically.
    }
    
    Devise a solution to the critical section problem for n processes using this instruction. Instead, model your solution on the manner in which a bakery, for instance, serializes customer service by means of a number dispenser. Prove that your solution meets the three criteria of a solution to the critical section problem. Solutions which treat the FAI instruction as a ``glorified'' TAS instruction will be down-graded. Likewise, simple ports of the bakery algorithm will be down-graded.

  4. (15 pts.) A barbershop consists of a waiting room with N chairs, and the barber room containing the barber chair. If there are no customers to be served the barber goes to sleep. If a customer enters the barbershop and all chairs are busy, then the customer leaves the shop. If the barber is busy, then the customer sits in one of the available free chairs. If the barber is asleep, the customer wakes the barber up. Write pseudo-code for the cooperating barber and customer threads. In devising your solution, you may make use of queueing semaphores.



Thomas P. Kelliher
Mon Feb 2 10:20:48 EST 1998
Tom Kelliher