Return to Contents
- Read S&G, chapter 7
- 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
Four Conditions for Deadlock
All four conditions must be true for a deadlock to occur.
- mutual exclusion
- processes have exclusive control of resources
- hold and wait
- processes have some resources and wait for more
- example: Process 2 had mutex semaphores and waited for full condition
- no preemption
- resource cannot be removed from a process
- 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
- deadlock prevention
- 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
- deadlock avoidance
- Dijkstra's Banker's Algorithm: assumes foreknowledge of all processes
- useless in practice
- deadlock detection and recovery
- 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.
Sample Answer:
(a) - not shown
(b) Yes, deadlock could exist.
The four necessary conditions are all true.
-
mutual exclusion is true because the resource cannot be shared
-
hold and wait is true because process P2 holds
resource R4 but also requests (waits for) resource R2
-
no preemption is stated in the question
-
circular wait exists:
P2 wants R2 but R2 is held by P3, P3 wants R4 but R4 is held by P2
Return to Contents