UNIVERSITY OF WISCONSIN-MADISON
Computer Sciences Department
CS 537
Fall 2007
A. Arpaci-Dusseau
Sample Quiz #7 -- Deadlock and Scheduling

Problem 1: Conditions for Deadlock

There are four conditions that are necessary for deadlock to occur: mutual exclusion, hold and wait, no preemption, and circular wait. With deadlock prevention, the system ensures that deadlock does not occur by preventing one of these conditions from holding. Match each of the following techniques with the one deadlock condition that it prevents.

a.  Mutual exclusion
b.  Hold and wait
c.  No preemption
d.  Circular wait

_____ Impose a total ordering (or ranking) on how resources are acquired

_____ When a process requests a resource that is already held, 
      force the process holding the resource to release it

_____ Only allow a process to request a resource when the process has none

_____ Allow all processes to access the resource simultaneously

_____ Require each process to grab all desired resources at once

Problem 2: Existance of Deadlock

Can running each of the following code segments lead to deadlock of process 0 and process 1? Simply answer "yes" or "no".

 Code Sample 1

Process 0:                Process 1:


lock1.acquire();          lock1.acquire();
lock2.acquire();          lock2.acquire();
lock1.release();          lock1.release();
lock2.release();          lock2.release();

 Code Sample 2

Process 0:                Process 1:


lock1.acquire();          lock2.acquire();
lock2.acquire();          lock1.acquire();
lock1.release();          lock1.release();
lock2.release();          lock2.release();

 Code Sample 3

Process 0:                Process 1:


lock1.acquire();          lock2.acquire();
lock2.acquire();          lock2.release();
lock1.release();          lock1.acquire();
lock2.release();          lock1.release();

Problem 3: Resource-Allocation Graph

Running which of the above code samples could lead to the situation shown in the following resource-allocation graph? Indicate all of the possible code samples that apply.

Resource allocation graph

Problem 4: General Scheduling

a) Consider a workload with 5 jobs that each compute for an identical amount of time, x, and that perform no I/O. To minimize the average waiting time of the jobs, should a FCFS scheduler or a RR scheduler be used?





b) Assume that job A is running on the CPU. Describe two circumstances in which a SJF scheduler will keep job A running, but a STCF scheduler will pick a different job.









Problem 5: Solaris Dispatch Table

To answer this problem, use the dispatch table that is appended at the end of the quiz (it is identical to the default dispatch table in Solaris).

a) Consider a process that is at priority 49.

  1. How long is the time-slice of this process?


  2. When the process consumes its time-slice, what will its new priority be?


  3. If the process is neither sleeping nor running when the 1 second update time expires, what will its new priority be?


  4. If the process is sleeping when the 1 second update timer expires, what will its new priority be?


b) Consider a workload containing only a single process. Assume that this process is completely CPU-bound. Draw a timeline showing the priority of that process for the first 600ms of its lifetime. In all of your timelines, clearly show both the priority of the job and the time at which the priority of the process changes. Assume that the 1 second update timer does not run in this interval. (Hint: Processes start at priority 29.)











c) Consider a new workload containing a single process; this process repeatedly computes for 20ms and then sleeps for 1000ms. Draw a timeline showing the priority of this process for 3 iterations of its compute/sleep cycle. You can assume that the 1 second update timer begins its cycle at the same time the process enters the system (i.e., the timer expires 1 second after the process begins executing).