Documente Academic
Documente Profesional
Documente Cultură
Fred Kuhns
(fredk@arl.wustl.edu, http://www.arl.wustl.edu/~fredk)
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
Introduction to deadlock
• Typical scenario for a process P:
– request exclusive access to some resource R
– process P uses the resource
– P then releases or returns the resource R to the system.
• Consumable resources
– Description:
• Created (produced) and destroyed (consumed) by a process
– Examples:
• Interrupts, signals, messages, and information in I/O buffers
• Deadlock can occur if two cars enter the bridge from opposite sides
– it can be resolved if one car backs up (preempt resources and rollback).
• Starvation is possible
– timid driver hesitates to enter bridge
P1 P2
... ...
Receive(P2); Receive(P1);
... ...
Send(P2); Send(P1);
• 2) Hold-and-wait:
– A process must hold at least one allocated resource while awaiting one or
more resources held by other processes.
• 3) No preemption:
– Resources not forcibly removed from a process holding it, the holding
process must voluntarily released it.
• 4) Circular wait
– a closed chain of processes exists, such that each process holds at least
one resource needed by the next process in the chain.
• V is partitioned into:
– P = {P1, P2, …, Pn}, all processes in the system.
– R = {R1, R2, …, Rm}, all resource types in the system.
P
• Process Pi
• Deadlock P1 P2
Fred Kuhns (01/17/09) CS422 – Operating Systems Concepts 9
Example of a Resource Allocation Graph
R1 R2 R1 R2 R1 R2
P1 P2 P3 P1 P2 P3 P1 P2 P3
R3 R4 R3 R4 R3 R4
• Avoidance ⇒
– ensure that a system will never enter an unsafe state.
Definitions
Resource = R = (R1, R2, ..., Rm) Available = V = (V1, V2, ..., Vm)
Relationships
M11 M12 ... M1m A11 A12 ... A1m n
M21 M22 ... M2m A21 A22 ... A2m 1) Ri = Vi + Σ Aki, for all i
Max = M = Allocation = A =
... ... k=1
Mn1 Mn2 ... Mnm An1 An2 ... Anm 2) Mki ≤ Ri, for all k, i
3) Aki ≤ Mki, for all k, i
N11 N12 ... N1m
N21 N22 ... N2m
Need = N = Max - Allocation =
...
Nn1 Nn2 ... Nnm
• If X and Y are vectors then X < Y iff X[i] < Y[i] for all i
• Row i of a matrix corresponds to process Pi. So Mi is the set of
maximum allocations for process i.
Fred Kuhns (01/17/09) CS422 – Operating Systems Concepts 20
Deadlock Avoidance Policies
• Deadlock Avoidance Policy – Process Initiation Denial
– Start if the max claim of all process can be met (including new
process)
– Start a new process Pn+1 only if the below inequality holds
n
Ri ≥ M(n+1)i + Σ Mki for all i
k=1
• If Finish [i] == True for all i, then the system is in a safe state.
Otherwise it is unsafe.
Fred Kuhns (01/17/09) CS422 – Operating Systems Concepts 22
Resource-Request Algorithm for Pi
• Detection algorithm
• Recovery scheme
R3 R4 P4
P4
Wait-For
Resource Allocation Graph
Graph
• Maintain wait-for graph
– Nodes are processes.
– Pi → Pj if Pi is waiting for Pj.
• Periodically invoke an algorithm that searches for a cycle in the
graph.
Fred Kuhns (01/17/09) CS422 – Operating Systems Concepts 28
Several Instances ea Resource Type
• Available: A vector of length m indicates the number of available
resources of each type.