UNIVERSITY OF WISCONSIN-MADISON
Computer Sciences Department
CS 537
Spring 2001
A. Arpaci-Dusseau
Quiz #5: March 21st -- Deadlock
Name: Student ID #:

Problem 1: Conditions for Deadlock (35 points)

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 (45 points)

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 (20 points)

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