Sample Midterm

  1. What are the values of the integer variables x and y when the following program completes? (If either variable could have more than one value, say why.)
    	y = 2;
    	parbegin
    		x = y * 2;
    		y = 6;
    	parend;
    
  2. Is the following true or false? Justify your answer. "When several processes access shared information in primary storage, mutual exclusion must be enforced to prevent the production of indeterminant results."
  3. Process A should finish before process B starts, and process B should finish before either of processes C or D start. Show how these processes may use two semaphores to provide the necessary synchronization.
  4. A bounded semaphore s is a counting semaphore that cannot exceed a given value smax > 0. The corresponding up and down operations are:
    up(s):   wait until s < smax; then increment s by 1
    down(s): wait until s > 0; then decrement s by 1
    
    Write a monitor to implement bounded semaphores. (Hint: assume the semaphore is to be initialized to the constant SINIT and the maximum value is SMAX.)
  5. Suppose a scheduling algorithm (at the level of short-term scheduling) favors those programs which have used little processor time in the recent past. Why will this algorithm favor I/O bound programs and yet not permanently starve CPU bound programs?
  6. Assume you have been given the following jobs with the indicated arrival and service times:
    name arrival time service time
    A 0 3
    B 2 5
    C 4 2
    D 6 1
    E 8 4
    1. When, and in what order, would these jobs run if the scheduling algorithm were first come first serve?
    2. When, and in what order, would these jobs run if the scheduling algorithm were shortest job next?
    3. When, and in what order, would these jobs run if the scheduling algorithm were round robin with a quantum of 2? Assume that if events are scheduled to happen at exactly the same time, that new arrivals precede terminations, which precede quantum expirations.

You can also obtain a PDF version of this. Version of April 27, 2008 at 7:58 PM