Homework 7: Deadlock and scheduling
CSE 410, Autumn 1999
Due in class, November 22nd

Reading

Scheduling: S+G Chapter 5, sections 1, 2, 3, and 6.1.
Deadlock: S+G Chapter 7, sections 1, 2.1, 3, 4, 5.1, 6, and 7.

To be turned in

S+G problems 5.3, 5.4, 5.5, 7.1, 7.4, and 7.12.

Extra Credit: Here is a function to move an item from one queue to another. Locking is used (a) to keep the queue structures consistent and (b) so that the item appears to be on one queue or the other at all times. Unfortunately, the code has a deadlock problem. Show how deadlock can occur and rewrite the function to be deadlock-free while preserving properties (a) and (b) and allowing maximal concurrency in the system.


void TransferItem(queue* q1, queue* q2) {
    q1->P();
    item* i = q1->dequeue();
    if(i != NULL) {
        q2->P();
	q2->enqueue(i);
	q2->V();
    }
    q1->V();
}