+ All Categories
Home > Documents > Cut-off theorems for deadlocks and...

Cut-off theorems for deadlocks and...

Date post: 24-Mar-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
57
Cut-off theorems for deadlocks and serializability Lisbeth Fajstrup Department of Mathematics Aalborg University Bedlewo 2013 Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 1 / 42
Transcript
Page 1: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Cut-off theorems for deadlocks and serializability

Lisbeth Fajstrup

Department of MathematicsAalborg University

Bedlewo 2013

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 1 / 42

Page 2: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Cut-Off Theorems

General

Property P holds for all n ∈ N if and only P holds for n ≤ M

Think of n as a dimension.Here: Given a computer program T , T n means n copies of T run inparallel.The properties P is deadlock free in one theorem and serializable in theother.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 2 / 42

Page 3: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Parallel program: Dining Philosophers

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 3 / 42

Page 4: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Parallel programs - several models

A non-parallel program is modelled as a graph. Loops, branches.Parallel programs interact. Share resources. May get conflicts. Severalmodels.

Petri Nets

Interleaving semantics

Here: Locks.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 4 / 42

Page 5: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

The Swiss flag - two dining philosophers.

T1 = PaPbVbVa, T2 = PbPaVaVb

Pa Pb Vb Va

Pb

Pa

Va

Vb

A

B

T1

T2

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 5 / 42

Page 6: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

PV -programs - controlling concurrency through locks

A set of shared resources R - memory, printers,...

A capacity function κ : R → N.

PV programs p are defined by the grammar

p ::= Pa | Va | p.p | p|p | p + p | p∗

Pa is a request to access the resource a, if granted acces, lock it. Va

releases the resource.

A program without the parallel operator is a thread.

Resource r may be locked by at most κ(r) threads at a time.

At a final point, the program has released all resources.

At an initial point, no resources are locked

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 6 / 42

Page 7: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

GeometricallyOne thread is represented by a graph. n threads in parallel is representedby a product of n graphs with “holes” where a resource is locked above itscapacity.

T1 = T2 = Pa.Pb.Va.Pa.Vb.Va κ ≡ 1

Pa Pb Va Pa Vb Va

Pa

Pb

Va

Pa

Vb

Va

A

A

A

A

B

T1

T2

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 7 / 42

Page 8: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

An execution is a directed path

Pa Pb Va Pa Vb Va

Pa

Pb

Va

Pa

Vb

Va

A

A

A

A

B

T1

T2

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 8 / 42

Page 9: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Deadlock - no time-directed paths leave the point

Pa Pb Va Pa Vb Va

Pa

Pb

Va

Pa

Vb

Va

A

A

A

A

B

T1

T2

The red region is unsafe. No directed path leaves it. The red balls aredeadlock points.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 9 / 42

Page 10: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

A few words about directed topologyTopological spaces with direction

Definition

Objects of dTop are d-Spaces: (X , ~P(X )) where X ∈ Top, ~P(X ) ⊆ X I ,the dipaths. ~P(X ) is

closed under concatenation,

contains the constant paths

closed under subpath, i.e., composition with f : I → I increasing butnot necessarily surjective.

A d-map f : X → Y is a continuous map satisfyingγ ∈ ~P(X )⇒ f ◦ γ ∈ ~P(Y )

Main examples: Directed paths are paths which are locally increasing wrt.a reasonable local order structure.

In computer science:

X is a state space. ~P(X ) are (partial) executions.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 10 / 42

Page 11: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Equivalence of executions

Definition

Two dipaths γ0, γ1 ∈ ~P(X )(p, q) are dihomotopic, if there is a dimapH : I ×~I → X s.t. H(0, t) = γ0(t), H(1, t) = γ1(t), H(I , 0) = p,H(I , 1) = q. (Dipaths in I are constant. Dipaths in ~I are non-decreasing)

The following are equivalent.

Execution paths γ1, γ2 : ~I → X are dihomotopic

They are in the same component of the path space ~P(X )(0, 1)(Compact-Open topology)

They are in the same component of the trace space ~T (X )(0, 1)(Paths modulo directed reparametrization)

Raussens algorithm

Calculates a prod-simplicial model of ~T (X )(0, 1), when X = I n \ F , F is aunion of n-rectangles. RedHom then calculates homology.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 11 / 42

Page 12: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Definition

A state x = (x1, . . . , xn) ∈ T1× T2× · · · × Tn is a deadlock if

The only dipaths starting in x are constant.

x is reachable: There is a dipath from 0 to x

x 6= > - not all Ti have finished

If x is a deadlock, then xi = > or xi = Pr(i) and κ(r(i)) other threadshold a lock on r(i) at x

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 12 / 42

Page 13: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

A cut-off theorem for deadlocks

Theorem 1

Let T be a PV thread accessing resources R with capacity κ : R → N.Let T n be n copies of T run in parallel.T n is deadlock free for all n if and only if TM is deadlock free, whereM = Σr∈Rκ(r).

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 13 / 42

Page 14: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

The bound M is sharp.

Theorem 2

Given R = {r1, . . . , rk} with capacity κ : R → N, the threadT = Pr1Pr2Vr1Pr3Vr2 . . .PrkVrk−1Pr1VrkVr1 satisfies:

There is a deadlock in TM (and hence for all n ≥ M)

There are no deadlocks in T n for n ≤ M

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 14 / 42

Page 15: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

The bound M is sharp.

Theorem 2

Given R = {r1, . . . , rk} with capacity κ : R → N, the threadT = Pr1Pr2Vr1Pr3Vr2 . . .PrkVrk−1Pr1VrkVr1 satisfies:

There is a deadlock in TM (and hence for all n ≥ M)

There are no deadlocks in T n for n ≤ M

Proof: The deadlock is x = (x1, . . . , x1, x2, . . . , x2, . . . , xk . . . xk) where fori 6= 1, xi = Pri and xi is repeated κ(ri−1) times. x1 is the last Pr1 and isrepeated κ(rk) times. All resources r are locked κ(r) times.Hence x is a deadlock and 6= >. (Need to check reachability and nodeadlocks in lower dimensions)

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 14 / 42

Page 16: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Example. When κ ≡ 1

x = (x1, x2, . . . , xk) and M = k :

T1 requests r1 and has a lock on rk

Ti requests ri and has a lock on ri+1

There are no deadlocks in T n for n < M: If y is a deadlock, then there isa yi1 = Pr(i1) and another yi2 with a lock on r(i1), so yi2 = Pr(i1 + 1)(or the last P(r1) if r(i1) = rk .Hence, y is a permutation of (x,>,>, . . . ,>).For κ 6= 1 the argument is similar. Still need to see that x is reachable.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 15 / 42

Page 17: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

ExampleT = PaPbVaPcVbPaVcVa, κ ≡ 1. T 3 has a deadlock at(6, 2, 4), (2, 4, 6), (6, 4, 2), (2, 6, 4), (4, 2, 6), (4, 6, 2)

Pa Pb Va Pc Vb Pa Vc Va

Pa

Pb

Va

Pc

Vb

Pa

Vc

Va

A

A

A

A

B

C

T1

T2

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 16 / 42

Page 18: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Proof of Theorem 2 continued

T = Pr1Pr2Vr1Pr3Vr2 . . .PrkVrk−1Pr1VrkVr1

x = (

κ(rk )︷ ︸︸ ︷x1, . . . , x1,

κ(r1)︷ ︸︸ ︷x2, . . . , x2, . . . ,

κ(rk−1)︷ ︸︸ ︷xk . . . xk) = (x1, x2, . . . , xk) is a deadlock:

For i 6= 1, xi = Pri and xi is repeated κ(ri−1) times. Holds κ(ri−1)locks on ri−1

x1 is the last Pr1 and is repeated κ(rk) times. Holds κ(rk) locks on rk

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 17 / 42

Page 19: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

x is reachable

(T = Pr1Pr2Vr1Pr3Vr2 . . .PrkVrk−1Pr1VrkVr1)a dipath from 0 to x is composed of the pieces:

γ0 : 0→ (x1, 0) serially - one coordinate at a time. OBS, now holdκ(rk) locks on rk

γ1 : (x1, 0)→ (x1, 0, xk) one coordinate at a time. Now also κ(rk−1)locks on rk−1

γj : (x1, 0, xk−j+2, . . . , xk)→ (x1, 0, xk−j+1, . . . , xk). Now κ(ri ) lockson rk−j , . . . , rk .

For γ0: ρi (γ0(t)) ≤ 1 for i 6= k ρk(γ0(t)) ≤ κ(rk).

ρi (γ1(t)) ≤ 1 for i 6= k − 1, k. ρk(γ1(t)) = k . ρk−1(γ1(t)) ≤ κ(rk−1).

ρi (γj(t)) ≤ 1 for i ≤ k − j + 1. ρi (γj(t)) = κ(ri ) for i ≥ k − j + 2.ρk−j+1(γj(t)) ≤ κ(rk−j+1).

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 18 / 42

Page 20: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

x is reachable

(T = Pr1Pr2Vr1Pr3Vr2 . . .PrkVrk−1Pr1VrkVr1)a dipath from 0 to x is composed of the pieces:

γ0 : 0→ (x1, 0) serially - one coordinate at a time. OBS, now holdκ(rk) locks on rk

γ1 : (x1, 0)→ (x1, 0, xk) one coordinate at a time. Now also κ(rk−1)locks on rk−1

γj : (x1, 0, xk−j+2, . . . , xk)→ (x1, 0, xk−j+1, . . . , xk). Now κ(ri ) lockson rk−j , . . . , rk .

For γ0: ρi (γ0(t)) ≤ 1 for i 6= k ρk(γ0(t)) ≤ κ(rk).

ρi (γ1(t)) ≤ 1 for i 6= k − 1, k. ρk(γ1(t)) = k . ρk−1(γ1(t)) ≤ κ(rk−1).

ρi (γj(t)) ≤ 1 for i ≤ k − j + 1. ρi (γj(t)) = κ(ri ) for i ≥ k − j + 2.ρk−j+1(γj(t)) ≤ κ(rk−j+1).

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 18 / 42

Page 21: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

x is reachable

(T = Pr1Pr2Vr1Pr3Vr2 . . .PrkVrk−1Pr1VrkVr1)a dipath from 0 to x is composed of the pieces:

γ0 : 0→ (x1, 0) serially - one coordinate at a time. OBS, now holdκ(rk) locks on rk

γ1 : (x1, 0)→ (x1, 0, xk) one coordinate at a time. Now also κ(rk−1)locks on rk−1

γj : (x1, 0, xk−j+2, . . . , xk)→ (x1, 0, xk−j+1, . . . , xk). Now κ(ri ) lockson rk−j , . . . , rk .

For j = 2, . . . , k − 1.

For γ0: ρi (γ0(t)) ≤ 1 for i 6= k ρk(γ0(t)) ≤ κ(rk).

ρi (γ1(t)) ≤ 1 for i 6= k − 1, k. ρk(γ1(t)) = k . ρk−1(γ1(t)) ≤ κ(rk−1).

ρi (γj(t)) ≤ 1 for i ≤ k − j + 1. ρi (γj(t)) = κ(ri ) for i ≥ k − j + 2.ρk−j+1(γj(t)) ≤ κ(rk−j+1).

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 18 / 42

Page 22: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

x is reachable(T = Pr1Pr2Vr1Pr3Vr2 . . .PrkVrk−1Pr1VrkVr1)a dipath from 0 to x is composed of the pieces:

γ0 : 0→ (x1, 0) serially - one coordinate at a time. OBS, now holdκ(rk) locks on rk

γ1 : (x1, 0)→ (x1, 0, xk) one coordinate at a time. Now also κ(rk−1)locks on rk−1

γj : (x1, 0, xk−j+2, . . . , xk)→ (x1, 0, xk−j+1, . . . , xk). Now κ(ri ) lockson rk−j , . . . , rk .

For j = 2, . . . , k − 1.Need: No resource is locked above its capacity along γ. Let ρi (y) be thenumber of locks held on ri at y ∈ TM .

For γ0: ρi (γ0(t)) ≤ 1 for i 6= k ρk(γ0(t)) ≤ κ(rk).

ρi (γ1(t)) ≤ 1 for i 6= k − 1, k. ρk(γ1(t)) = k . ρk−1(γ1(t)) ≤ κ(rk−1).

ρi (γj(t)) ≤ 1 for i ≤ k − j + 1. ρi (γj(t)) = κ(ri ) for i ≥ k − j + 2.ρk−j+1(γj(t)) ≤ κ(rk−j+1).

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 18 / 42

Page 23: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

x is reachable(T = Pr1Pr2Vr1Pr3Vr2 . . .PrkVrk−1Pr1VrkVr1)a dipath from 0 to x is composed of the pieces:

γ0 : 0→ (x1, 0) serially - one coordinate at a time. OBS, now holdκ(rk) locks on rk

γ1 : (x1, 0)→ (x1, 0, xk) one coordinate at a time. Now also κ(rk−1)locks on rk−1

γj : (x1, 0, xk−j+2, . . . , xk)→ (x1, 0, xk−j+1, . . . , xk). Now κ(ri ) lockson rk−j , . . . , rk .

For j = 2, . . . , k − 1.Need: No resource is locked above its capacity along γ. Let ρi (y) be thenumber of locks held on ri at y ∈ TM .

For γ0: ρi (γ0(t)) ≤ 1 for i 6= k ρk(γ0(t)) ≤ κ(rk).

ρi (γ1(t)) ≤ 1 for i 6= k − 1, k. ρk(γ1(t)) = k . ρk−1(γ1(t)) ≤ κ(rk−1).

ρi (γj(t)) ≤ 1 for i ≤ k − j + 1. ρi (γj(t)) = κ(ri ) for i ≥ k − j + 2.ρk−j+1(γj(t)) ≤ κ(rk−j+1).

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 18 / 42

Page 24: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Proof of theorem 1

Theorem 1

Let T be a PV thread accessing resources R with capacity κ : R → N.Let T n be n copies of T run in parallel.T n is deadlock free for all n if and only if TM is deadlock free, whereM = Σr∈Rκ(r).

Prove: If there is a deadlock in T n, then there is a deadlock in TM .

For n < M: Suppose x = (x1, . . . , xn) is a (reachable) deadlock in T n.Then for all i, either xi = Prj(i) and ρj(i)(x) = κ(rj(i)) or xi = >.

Then x̃ = (x1, . . . , xn,>, . . . ,>) ∈ TM is a (reachable) deadlock in TM ,since

ρi (x̃) = ρi (x) for all i

x̃ is reachable: There is a serial path to (0,>, . . . ,>). Compose with(γ(t),>, . . . ,>), where γ(t) : 0→ x ∈ T n

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 19 / 42

Page 25: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Proof of theorem 1

Theorem 1

Let T be a PV thread accessing resources R with capacity κ : R → N.Let T n be n copies of T run in parallel.T n is deadlock free for all n if and only if TM is deadlock free, whereM = Σr∈Rκ(r).

Prove: If there is a deadlock in T n, then there is a deadlock in TM .For n < M: Suppose x = (x1, . . . , xn) is a (reachable) deadlock in T n.Then for all i, either xi = Prj(i) and ρj(i)(x) = κ(rj(i)) or xi = >.

Then x̃ = (x1, . . . , xn,>, . . . ,>) ∈ TM is a (reachable) deadlock in TM ,since

ρi (x̃) = ρi (x) for all i

x̃ is reachable: There is a serial path to (0,>, . . . ,>). Compose with(γ(t),>, . . . ,>), where γ(t) : 0→ x ∈ T n

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 19 / 42

Page 26: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Proof of theorem 1

Theorem 1

Let T be a PV thread accessing resources R with capacity κ : R → N.Let T n be n copies of T run in parallel.T n is deadlock free for all n if and only if TM is deadlock free, whereM = Σr∈Rκ(r).

Prove: If there is a deadlock in T n, then there is a deadlock in TM .For n < M: Suppose x = (x1, . . . , xn) is a (reachable) deadlock in T n.Then for all i, either xi = Prj(i) and ρj(i)(x) = κ(rj(i)) or xi = >.

Then x̃ = (x1, . . . , xn,>, . . . ,>) ∈ TM is a (reachable) deadlock in TM ,since

ρi (x̃) = ρi (x) for all i

x̃ is reachable: There is a serial path to (0,>, . . . ,>). Compose with(γ(t),>, . . . ,>), where γ(t) : 0→ x ∈ T n

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 19 / 42

Page 27: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Proof of Theorem 1. n > M

x = (x1, . . . , xn) is a (reachable) deadlock in T n.

Construct the directed wait for graph G (x) = (V ,E ).

V = {x1, . . . , xn}

There is an edge E (xi , xk) if xi = Prj and ρj(xk) = 1.Properties of G (x)

If xi = >, then the vertex xi is isolated.

If xi = Prj , then the vertex xi has κ(rj) outgoing edges.

Hence, there are circuits in G (x): Start a walk at a non-isolatedvertex. If xj is the target of an edge, then xj 6= >, so the walkcontinues. G (x) is finite, so there is a circuit L.

Let ↑ L be the vertices reachable from L.Let x̃ = (xi1 , xi2 , . . . , xim) where xij are all the vertices in ↑ L

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 20 / 42

Page 28: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Proof of Theorem 1. n > M

x = (x1, . . . , xn) is a (reachable) deadlock in T n.Construct the directed wait for graph G (x) = (V ,E ).

V = {x1, . . . , xn}

There is an edge E (xi , xk) if xi = Prj and ρj(xk) = 1.

Properties of G (x)

If xi = >, then the vertex xi is isolated.

If xi = Prj , then the vertex xi has κ(rj) outgoing edges.

Hence, there are circuits in G (x): Start a walk at a non-isolatedvertex. If xj is the target of an edge, then xj 6= >, so the walkcontinues. G (x) is finite, so there is a circuit L.

Let ↑ L be the vertices reachable from L.Let x̃ = (xi1 , xi2 , . . . , xim) where xij are all the vertices in ↑ L

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 20 / 42

Page 29: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Proof of Theorem 1. n > M

x = (x1, . . . , xn) is a (reachable) deadlock in T n.Construct the directed wait for graph G (x) = (V ,E ).

V = {x1, . . . , xn}

There is an edge E (xi , xk) if xi = Prj and ρj(xk) = 1.Properties of G (x)

If xi = >, then the vertex xi is isolated.

If xi = Prj , then the vertex xi has κ(rj) outgoing edges.

Hence, there are circuits in G (x): Start a walk at a non-isolatedvertex. If xj is the target of an edge, then xj 6= >, so the walkcontinues. G (x) is finite, so there is a circuit L.

Let ↑ L be the vertices reachable from L.Let x̃ = (xi1 , xi2 , . . . , xim) where xij are all the vertices in ↑ L

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 20 / 42

Page 30: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Proof of Theorem 1. n > M

x = (x1, . . . , xn) is a (reachable) deadlock in T n.Construct the directed wait for graph G (x) = (V ,E ).

V = {x1, . . . , xn}

There is an edge E (xi , xk) if xi = Prj and ρj(xk) = 1.Properties of G (x)

If xi = >, then the vertex xi is isolated.

If xi = Prj , then the vertex xi has κ(rj) outgoing edges.

Hence, there are circuits in G (x): Start a walk at a non-isolatedvertex. If xj is the target of an edge, then xj 6= >, so the walkcontinues. G (x) is finite, so there is a circuit L.

Let ↑ L be the vertices reachable from L.Let x̃ = (xi1 , xi2 , . . . , xim) where xij are all the vertices in ↑ L

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 20 / 42

Page 31: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

x̃ = (xi1 , xi2 , . . . , xim) where xij are all the vertices in ↑ L, future of a circuitin the wait-for-graph.Claim:

1 x̃ is a (reachable) deadlock.

2 m ≤ M

Reachability: Let γ : 0→ x in T n. The restriction to Ti1, . . .Tim is adipath 0→ x̃

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 21 / 42

Page 32: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

The Wait for Graph - the loop

xi1

xi2 xi3

xi4

xi5

xil

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 22 / 42

Page 33: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

The restricted Wait for Graph - future of the loop

xi1

xi2 xi3

xi4

xi5

xil

κ(r(il)) locks

κ(r(i1)) locks

κ(r(i1)) edges

xij 6= >, so xij = P(r(ij)). In G (x), xij = P(r(ij)) had κ(r(ij)) outgoingedges. It still has in G (x̃), since ↑ L contains all targets.

Hence, x̃ is a deadlock.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 23 / 42

Page 34: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

m ≤ M

In G (x̃), all the m vertices are targets. Hence, they hold a lock on aresource.

The maximal number of locks at an allowed state is M = Σr∈Rκ(r)

Hence, there are at most M vertices in G (x̃) (Less, if some xi hold alock on more than one resource.)

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 24 / 42

Page 35: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Now to something different: Serializability

Pa Pb Va Pa Vb Va

Pa

Pb

Va

Pa

Vb

Va

A

A

A

A

B

T1

T2

Two executions up to dihomotopy. Equivalent to the serial executionsT1.T2 and T2.T1

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 25 / 42

Page 36: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

SerializabilityT = PaPbVaPcVbPaVcVa is not serializable.

Pa Pb Va Pc Vb Pa Vc Va

Pa

Pb

Va

Pc

Vb

Pa

Vc

Va

A

A

A

A

B

C

T1

T2

4 Executions up to dihomotopy. Two serial executions (green). Twonon-serializable executions (red).

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 26 / 42

Page 37: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Serializability - a cut-off theorem

Definition

T1|T2 . . . |Tn is serializable if all execution paths are dihomotopic to aserial execution Ti1.Ti2....Tin.

Theorem 3

Let T be a PV -thread accessing resources R all of capacity 1.Let T n be n copies of T run in parallel. Then T n is serializable if and onlyif T 2 is serializable.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 27 / 42

Page 38: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

In general pairwise serializability is not enough

Example

Let T1 = PcVcPaVa, T2 = PcVcPbVb, T3 = PaVaPbVb,Each pair Ti ,Tj shares one resource.

T1

T2

T3

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 28 / 42

Page 39: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Schedules as in Raussens Trace algorithm

When κ = 1

All conflict n-rectangles are ×nk=1Ik , Ik = I except for two directions

Ii =]ai , bi [, Ij =]aj , bj [

One choice at a given such n-rectangle “above or below” in theij-plane - i waits or j waits.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 29 / 42

Page 40: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

T = PaVa, T 3

T

T

T

3! serial executions, pairwise inequivalent.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 30 / 42

Page 41: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

T n

Each pair of locked intervals ]a1, b1[, ]a2, b2[ in T gives n · (n − 1)forbidden n-rectangles in T n

Ri ,j = ×nk=1Ik

Ii =]a1, b1[, Ij =]a2, b2[, Ik = I otherwise.

The diagonal rectangles in T 2 give ×nk=1Ik Ii =]a, b[, Ij =]a, b[,

Ik = I , n·(n−1)2 n-rectangles. Intersecting in ]a, b[×]a, b[× · · ·×]a, b[.

If T is non-trivial, all the n! serial executions are non-equivalent, since

They have different schedules wrt. the n·(n−1)2 n-rectangles induced

by just one PV -interval.

Equivalently: Their projections to at least one of the T 2 arenon-equivalent.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 31 / 42

Page 42: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

The symmetric case T 2

k instances of Pa,Va gives k2 forbidden rectangles in T 2

T = PaPbVaPcVbPaVcVa

PaPbVaPc VbPaVc Va

Pa

Pb

Va

Pc

Vb

Pa

Vc

Va

A

A

A

A

B

C

T1

T2

4 rectangles labelled A.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 32 / 42

Page 43: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

T 2 serializability

If choice at one rectangle implies choice at all other rectangles -below all or above all rectangles

Equivalently: The closure of the forbidden area under addingunreachable and unsafe areas is connected. (Yannakakis,Papadimitriou, Kung,1979)

OBS: Two phase locking is not required.

PaPbVaPcVbPdVcVd

PaPbVaPcVbPdVcVd

A

D

B

C

T1

T2

PaPbVa PaVbVa

Pa

Pb

Va

Pa

Vb

Va

A

A

A

A

B

T1

T2

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 33 / 42

Page 44: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

T 2 serializability

If choice at one rectangle implies choice at all other rectangles -below all or above all rectangles

Equivalently: The closure of the forbidden area under addingunreachable and unsafe areas is connected. (Yannakakis,Papadimitriou, Kung,1979)

OBS: Two phase locking is not required.

PaPbVaPcVbPdVcVd

PaPbVaPcVbPdVcVd

A

D

B

C

T1

T2

A

A

A

A

B

Pd Pd PdVd Vd Vd

Pd

Pd

Pd

Vd

Vd

Vd

D D

DD

D

D DD

D

T1

T2

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 33 / 42

Page 45: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Proof of Theorem 3

Suppose T 2 is serializable, then

1 Let ]ar , br [ correspond to a lock Pr ,Vr . There are n! schedules forthe rectangles {×n

k=1Ik , Ik =]ar , br [ for k = i , j , i < j ∈ [1 : n]} -corresponding to the serial executions.

2 Fix i , j . There are two schedules - i last for all or j last for all therectangles {I × I × · · ·×]ars , b

rs [×I · · · ×]art , b

rt [×I × · · · × I} where

]ars , brs [×]art , b

rt [ are forbidden rectangles in T 2

3 Choose one of the n! schedules for 1); that fixes all schedules in 2).Hence, there are n! inequivalent schedules.

4 These are all realized by serial executions.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 34 / 42

Page 46: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

How complicated does T n get?

Answer: Very!

1 Let T1, . . . ,Tk be threads. Compose to get T = T1.T2. . . . .Tk.

2 T1× . . .×Tk ↪−→ T k at [0, 1]× [1, 2]× . . .× [k − 1, k] (and at the k!permutations)

3 All paths on the integer 1-skeleton are allowed (serial execution ofTi).(Ti holds no locks at ⊥ and >)

4 Hence, the lower point (0, 1, 2, . . . , k − 1) is reachable from 0 andthere is a path from (1, 2, . . . , k) to k.

5 So deadlocks, non-serializable paths etc. in T1× . . .× Tk arerealized in T k .

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 35 / 42

Page 47: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Serializability for κ > 1

There are non-serializable executions.

All serial executions are equivalent (all boundary 2-cells are allowed)

The scheduling algorithm calculates components of the trace space.

More than one component ⇔ non-serializable.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 36 / 42

Page 48: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

The scheduling algorithm

X = I n \ F , F = ∪li=1Ri

R i =]ai1, bi1[× . . .×]ain, b

in[

Use the Nerve Lemma for a covering of ~P(X )(0, 1), the space of dipaths.Output: A prod-simplicial model of ~P(X )(0, 1). Then RedHom calculateshomology.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 37 / 42

Page 49: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

X = I n \ F , F = ∪li=1Ri

R i =]ai1, bi1[× . . .×]ain, b

in[

A schedule is an l-tuple J = (J1, . . . , Jl) where Ji ⊂ {1 . . . , n}. Thethreads/directions/coordinates which wait till at least one (other) haspassed R i .J defines a subset of ~P(X )(0, 1):

Extend R i according to Ji - if j ∈ Ji , thenR ij = [0, bi1[× . . .×]aij , b

ij [× . . .× [0, bin[.

FJ = ∪li=1 ∪j∈Ji R ij

XJ = I n \ FJ~P(XJ)(0, 1) is an open subset of ~P(X )(0, 1), either empty or contractible(when Ji 6= ∅ for all i).~P(XJ)(0, 1) ∩ ~P(XJ′)(0, 1) = ~P(XJ∪J′)(0, 1)

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 38 / 42

Page 50: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

A non-serializable κ = 2 example.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 39 / 42

Page 51: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Schedule for “two wedges”

J = ({3}, {3}, {2}, {1})Paths following this schedule go through the “hole”.

J1 = ({1, 3}, {3}, {2}, {1}) and J2 = ({3}, {2, 3}, {2}, {1}) also“through the hole”.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 40 / 42

Page 52: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Schedule for “two wedges”

J = ({3}, {3}, {2}, {1})Paths following this schedule go through the “hole”.

J1 = ({1, 3}, {3}, {2}, {1}) and J2 = ({3}, {2, 3}, {2}, {1}) also“through the hole”.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 40 / 42

Page 53: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Schedule for “two wedges”

J = ({3}, {3}, {2}, {1})Paths following this schedule go through the “hole”.

J1 = ({1, 3}, {3}, {2}, {1}) and J2 = ({3}, {2, 3}, {2}, {1}) also“through the hole”.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 40 / 42

Page 54: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Schedule for “two wedges”

J = ({3}, {3}, {2}, {1})Paths following this schedule go through the “hole”.

J1 = ({1, 3}, {3}, {2}, {1}) and J2 = ({3}, {2, 3}, {2}, {1}) also“through the hole”.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 40 / 42

Page 55: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Schedule for “two wedges”

J = ({3}, {3}, {2}, {1})Paths following this schedule go through the “hole”.

J1 = ({1, 3}, {3}, {2}, {1}) and J2 = ({3}, {2, 3}, {2}, {1}) also“through the hole”.

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 40 / 42

Page 56: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

Non-serializability for two wedges

J = ({3}, {3}, {2}, {1})Paths following this schedule go through the “hole”.

J1 = ({1, 3}, {3}, {2}, {1}) and J2 = ({3}, {2, 3}, {2}, {1}) also“through the hole”.

Non-serializable. Since Ji < J̃ ⇒ ~P(XJ̃) = ∅Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 41 / 42

Page 57: Cut-off theorems for deadlocks and serializabilitybcc.impan.pl/13AppTop/uploads/prezentacje/LisbethFajstrup.pdf · Cut-O Theorems General Property Pholds for all n 2N if and only

More to do

Serializability for κ > 1 - Guess: There is a homological obstruction .This needs to be described specifically for the symmetric case.

As of last night: Proof that κ = 2 has cut-off at n = 3, but thatneeds checking in daylight....

Cut-off for other properties - linearizability?

Lisbeth Fajstrup (AAU) Cut-Off Theorems July 2013 42 / 42


Recommended