• two or more processes are each waiting for a resource held by another process
• if there are separate critical sections for two data structures, we have to be careful if we need both
• example of deadlock in a resource allocation graph

All four conditions must be true for a deadlock to occur.

1. mutual exclusion
• processes have exclusive control of resources

2. hold and wait
• processes have some resources and wait for more
• example: Process 2 had mutex semaphores and waited for full condition

3. no preemption
• resource cannot be removed from a process

4. circular wait
• a circular chain of processes exists in which each process holds one or more resources requested by the next process in the chain
• example: first must acquire empty or full before mutex

Three Ways of Dealing with Deadlock

• one--shot algorithm where you must acquire all resources or none!
• hierarchical algorithm: acquire resources in a set order; acquire low priority resources before high priority ones
ranked resources
first acquire R1
then acquire Rn

• Dijkstra's Banker's Algorithm: assumes foreknowledge of all processes
• useless in practice

• used in UNIX (most common in practice)
• deadlock occurs and then some processes are terminated and the mess is cleaned up

Sample Question:

(a) Draw the resource-allocation graph when the sets P, R, and E are:

P = {P1, P2, P3}

R = {R1, R2, R3, R4}

E = {P1 -->R1, P2 -->R1, P2 -->R2, P3 -->R4, R2 -->P3, R3 -->P1, and R4 -->P2}

Assume there exists one instance of each resource type. As well, assume resources R1, R2, R3, and R4 are nonpreemptive and cannot be shared.

(b) Could a deadlock exist in the system described in part (a)? Explain why or why not making reference to the necessary conditions for a deadlock.