UNIVERSITY OF WISCONSIN-MADISON
Computer Sciences Department | ||
CS 537
Fall 2007 | A. Arpaci-Dusseau | |
Sample Quiz #7 -- Deadlock and Scheduling |
a. Mutual exclusion b. Hold and wait c. No preemption d. Circular wait _d_ Impose a total ordering (or ranking) on how resources are acquired _c_ When a process requests a resource that is already held, force the process holding the resource to release it _b_ Only allow a process to request a resource when the process has none _a_ Allow all processes to access the resource simultaneously _b_ Require each process to grab all desired resources at once
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();No deadlock possible, because there is no circularity of requests. Both processes grab the locks in the same order. |
Code Sample 2 Process 0: Process 1: lock1.acquire(); lock2.acquire(); lock2.acquire(); lock1.acquire(); lock1.release(); lock1.release(); lock2.release(); lock2.release();Deadlock is possible, because there is circularity. If process 0 acquires lock1 and then process 1 acquires lock2, both will be stuck holding one lock while waiting for the other. |
Code Sample 3 Process 0: Process 1: lock1.acquire(); lock2.acquire(); lock2.acquire(); lock2.release(); lock1.release(); lock1.acquire(); lock2.release(); lock1.release();No deadlock possible, because process 1 does not hold and wait. Even if process 0 acquires lock1 and process 1 acquires lock2, eventually process 1 will release lock2, at which point process 0 will be able to acquire lock 2. |
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.
Possible with Code Sample 1 given the following execution:
Process 0: Process 1: lock1.acquire(); lock2.acquire(); lock1.acquire(); // waits! |
Not possible with Code Sample 2; if Process 1 is waiting for lock1, it must hold lock2, which isn't shown in the figure.
Possible with Code Sample 3 given the following execution:
Process 0: Process 1: lock2.acquire(); lock2.release(); lock1.acquire(); lock2.acquire(); lock1.acquire(); // waits! |
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.
a) Consider a process that is at priority 49.
Timeline is not drawn to scale. Pri: 29 19 9 0 |-----------|------------|-------------|----------| 0 120ms 280ms 480 600c) 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).
Timeline is not drawn to scale. Pri: 29 sleep 52 sleep 58 sleep |----|---------------------|----|----------------|----|-------------| 0 20ms 1020 1040 2040 2060 3060 When the update timer runs at 1000ms and 2000ms, it increments the dispwait variable of the job to 1. When the job wakes, it sees that dispwait > maxwait (0), so the priority of the job is raised to that specified by slpret and dispwait is set back to 0.