UNIVERSITY OF WISCONSIN-MADISON
Computer Sciences Department
CS 537
Spring 2000
A. Arpaci-Dusseau
Solutions to Quiz #4: Wednesday, March 8

Name: Student ID #:

Deadlock and CPU Scheduling

Problem 1: Deadlock (40 points)

Resource allocation graph

a) Consider the resource-allocation graph shown above. Show a sequence of lock.acquire() instructions performed by processes P1, P2, and P3 for locks R1, R2, and R3 that would lead to the state depicted in the resource-allocation graph. If there is more than one possible ordering for two or more acquire instructions, then do not place any artificial contraints on their ordering (i.e. show those instructions could run in a different order by placing them on the same line).



    P1                             P2                          P3

    R3.acquire(); R1.acquire();                                R2.acquire();

    R2.acquire();                  R1.acquire();               R1.acquire();

Note that there are other solutions that are also acceptable. b) Assume that these resources require mutual exclusion, that each process holds onto its current resource until it can acquire the next resource, and that resources cannot be preempted. Does deadlock exist in this system depicted by the resource-allocation graph? If not, explain why not. If so, list all possible processes that could be killed to remove the deadlock.

Because the first three conditions for deadlock hold and there is a
circularity of requests in the graph, deadlock exists.

Either Process P1 or P3 could be killed to remove the deadlock. Killing P2 doesn't help to remove the deadlock.

Problem 2: General Scheduling (30 points)

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?

FCFS (first-come-first-served) minimizes the average waiting time better
than RR (round-robin) whenever the computatation times of jobs in a
workload is identical.  

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.

SCTF (Shortest-completion-time-first) is a preemptive version of SJF
(Shortest-job-first).  Therefore, with STCF if a job with a shorter CPU
burst than the currently running job becomes READY, the READY job will be
scheduled over the currently running job; SJF will not schedule the ready
job.

As shown in Figure 4.1 in the textbook, there are two cases in which a
process enters the READY state.

1.  A new job enters the system.

2.  An I/O event completes for a job.

Problem 3: Scheduling with Priorities (30 points)

Consider the external sorting program that you wrote for Project 2, with reader, worker, and writer threads set to priorities high, medium, and low respectively. Assume that priorities are strictly followed within the Java thread scheduler. Also assume that the code for the worker thread is written such that it gives preference to partitioning if it is able to both partition and sort.

Consider the case where the program is run with a single worker thread, but with two read buffers, two sets of bucket buffers, and two write buffers. Assume that there are 96 keys in the input file and a buffer size of 32 keys.

Specify the order that the threads will run. Use notation such that r stands for the reader thread, p for the worker thread acting as a partitioner, s for the worker thread acting as a sorter, and w for the writer thread.


       r, r, p, r, p, s, p, s, w, s, w, w