Deadlock
COMP3151/9151 Foundations of Concurrency Lecture 10
Termination 2: Deadlock-Freedom
Kai Engelhardt
CSE, UNSW (and data61)
Revision: 1.5 of Date: 2017/10/09 01:00:47 UTC
1 Deadlock
Deadlock Classes
A non-terminated process is deadlocked if it cannot move anymore. In the context of concurrency:
A deadlock is a situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does. [wikipedia] In our setting of transition diagrams, there are two distinct causes for deadlock:
Message deadlock: The process blocks on a receive (or synchronous send) statement but no communication partner will ever execute the corresponding send (receive) statement. Resource deadlock: The process blocks in a state from which only guarded transition depart but none of the guards will ever become true again.
2 Deadlock
Deadlock-Avoidance by Order
A simple resource acquisition policy can be formulated that precludes resource deadlocks by avoiding cycles in wait-for-graphs.
[. . . ] assign a precedence to each resource and force processes to request resources in order of increasing precedence. [wikipedia] This is a common solution in OS and DB.
3 Deadlock
Deadlock-Avoidance by Resource-Scheduling
Around 1964 Dijkstra described a Banker’s Algorithm to overcome a problem he called deadly embrace [Dij64]. It requires both the number of processes and their resource needs to be static. It boils down to granting resources only if all resources a process needs can be granted at that time to avoid entering unsafe states in which more than one process holds partial sets of resources.
4 Deadlock
Deadlock for Transtion Diagrams
A transition ` −b→−f−→`0 is enabled in a state σ if its boolean condition b is satisfied in σ. A process is blocked at a location ` if it has not terminated (` 6= t) and none of its transitions are enabled there. A concurrent program is deadlocked if some of its processes are blocked and the remaining ones have terminated. Clearly, deadlock is an undesirable situation. How can we prove deadlock-freedom?
5 Deadlock
Characterisation of Blocking
Let P = P1 k ... k Pn, its precondition φ, and assume that for each process Pi = (Li , Ti , si , ti ) of P there is a local assertion network( Q`)`∈L V i satisfying all but the last condition (|= i Qti → ψ) of the Owicki/Gries method for proving {φ} P {ψ}.
Process Pi can only be blocked in state σ at non-final location ` ∈ Li \{ti } from which there are m transitions with boolean conditions b1,..., bm, respectively, if σ |= c`, where Wm c` = Q` ∧ ¬ k=1bk .
6 Deadlock
Characterisation of Blocking cont’d
Consequently, using predicates
B = W c i `∈Li \{ti } ` deadlock can only occur in a state σ if
Vn Wn σ |= i=1(Qti ∨ Bi ) ∧ i=1Bi holds. (Every process has terminated or blocked and at least one is blocked.)
7 Deadlock
Owicki/Gries Deadlock-Freedom Condition