CS 110 Homework Assignment 2
Due: Friday, March 8, 2002, at 9 PM

Turn in your assignments in the bin outside Geoff's office. Late homework will be penalized; see the late policy for more information. We also will not accept handwritten material or printouts in which long lines are wrapped in the middle of a word. We prefer that you use a text processor. You might try troff or latex in combination with xfig.

Also remember to date and time stamp your homework.

  1. 3 points:
    MOS #2.22, p. 154. Consider a computer that does not have a TSL instruction but does have an instruction to swap the contents of a register and a memory word in a single indivisible action. Can that be used to write a route enter_region such as the one found in Fig. 2-22?
  2. 3 points:
    MOS #2.31, p. 155. In the solution to the dining philosophers problem (Fig. 2-20), why is the state variable set to HUNGRY in the procedure take_forks?
  3. 3 points:
    MOS #2.32, p. 155. Consider the procedure put_forks in Fig. 2-20. Suppose that the variable state[i] was set to THINKING after the two calls to test, rather than before. How would this change affect the solution?
  4. 3 points:
    MOS #2.38, p. 156. Measurements of a certain system have shown that the average process runs for a time T before blocking on I/O. A process switch requires a time S, which is effectively wasted (overhead). For round-robin scheduling with quantum Q, give a formula for the CPU efficiency for each of the following:
    1. Q = infinity
    2. Q > T
    3. S < Q < T
    4. Q = S
    5. Q nearly 0
    Note: The CPU efficiency is defined as the CPU time spent doing useful work, divided by the total CPU time.
  5. 3 points:
    MOS #2.39, p. 156. Five jobs are waiting to be run. Their expected run times are 9, 6, 3, 5, and x. In what order should they be run to minimize average response time? (Your answer will be depend on x.)
  6. 3 points:
    MOS #2.44, p. 157. A soft real-time system has four periodic events with periods of 50, 100, 200, and 250 msec each. Suppose that the four events require 35, 20, 10, and x msec of CPU time, respectively. What is the largest value of x for which the system is schedulable?
  7. 5 points:
    Consider a variant of the RR (Round Robin) scheduling algorithm where the entries in the ready queue are pointers to the PCBs (Process Control Blocks).
    1. What would be the effect of putting two pointers to the same process in the ready queue?
    2. How would you modify the basic RR algorithm to achieve the same effect without the duplicate pointers?
  8. 3 points:
    Suppose that a scheduling algorithm favors those processes that have used the least processor time in the recent past. Why will this algorithm favor I/O bound programs and yet not permanently starve CPU-bound programs?
  9. 2 points:
    Log in to Turing. Run ps and determine:
    1. The parent process of ps, owned by you.
    2. The grandparent of ps.
    3. The longest chain of parent/child processes for your login session.
    4. The scheduling priority of your processes.

    Turn in an annotated script file of your ps answering the questions above.
  10. 3 points:
    MOS #2.50, p. 157. Consider a bathroom that can be used by members of either gender. When a person of one gender is present, other persons may enter, but persons of the opposite gender must wait until the bathroom is empty. A sign on the bathroom door indicates one of three states: Write pseudocode for the following procedures:
    1. woman_wants_to_enter
    2. man_wants_to_enter
    3. woman_leaves
    4. man_leaves
    You may use whatever counters and synchronization techniques you like.
  11. 4 points:
    Modify your solution to the previous problem to prevent starvation.

Last modified March 2, 2002 by geoff@cs.hmc.edu