\ formal - hating ' - algor . than \ output ' race ? has - - PowerPoint PPT Presentation

formal hating algor than output race has msc a joost
SMART_READER_LITE
LIVE PREVIEW

\ formal - hating ' - algor . than \ output ' race ? has - - PowerPoint PPT Presentation

Overview MSCS " in menon " o P interpretation their that complicates 1 Lecture 2: Races \ definition \ formal - hating ' - algor . than \ output ' race ? has Msc a Joost-Pieter Katoen Theoretical


slide-1
SLIDE 1 Overview 1 Lecture 2: Races Joost-Pieter Katoen Theoretical Foundations of the UML 1/23
  • menon
in MSCS that complicates

their

P " "

interpretation

  • \
formal definition

\

algor . than
  • '
hating \
  • utput
' Msc has a race ?
slide-2
SLIDE 2 Theoretical Foundations of the UML Lecture 2: Races Joost-Pieter Katoen Lehrstuhl für Informatik 2 Software Modeling and Verification Group moves.rwth-aachen.de/teaching/ss-20/fuml/ April 21, 2020 Joost-Pieter Katoen Theoretical Foundations of the UML 2/23
slide-3
SLIDE 3 Summary of Lecture #1 Joost-Pieter Katoen Theoretical Foundations of the UML 3/23
slide-4
SLIDE 4 Summary of Lecture #1 1 A Message Sequence Chart is a partial order between send and receive events totally ordered per process vertical ordering receive events happen after their send events message ordering respecting the first-in first out (FIFO) property Joost-Pieter Katoen Theoretical Foundations of the UML 3/23 p I ez
  • ez
> e ,

±

:

non 9 S p 5 ez < g e , Fito .
slide-5
SLIDE 5 Summary of Lecture #1 1 A Message Sequence Chart is a partial order between send and receive events totally ordered per process vertical ordering receive events happen after their send events message ordering respecting the first-in first out (FIFO) property 2 Linearizations are totally ordered extensions of partial orders all linearizations of an MSC are well-formed 1 every receive is preceded by a corresponding send 2 respects the FIFO ordering 3 no send events without corresponding receive Joost-Pieter Katoen Theoretical Foundations of the UML 3/23

{

slide-6
SLIDE 6 Summary of Lecture #1 1 A Message Sequence Chart is a partial order between send and receive events totally ordered per process vertical ordering receive events happen after their send events message ordering respecting the first-in first out (FIFO) property 2 Linearizations are totally ordered extensions of partial orders all linearizations of an MSC are well-formed 1 every receive is preceded by a corresponding send 2 respects the FIFO ordering 3 no send events without corresponding receive 3 Every well-formed word can be transformed into an MSC two linearizations of the same MSC yield isomorphic MSCs Joost-Pieter Katoen Theoretical Foundations of the UML 3/23 MIM I Liners
slide-7
SLIDE 7 Summary of Lecture #1 1 A Message Sequence Chart is a partial order between send and receive events totally ordered per process vertical ordering receive events happen after their send events message ordering respecting the first-in first out (FIFO) property 2 Linearizations are totally ordered extensions of partial orders all linearizations of an MSC are well-formed 1 every receive is preceded by a corresponding send 2 respects the FIFO ordering 3 no send events without corresponding receive 3 Every well-formed word can be transformed into an MSC two linearizations of the same MSC yield isomorphic MSCs 4 So: there is a 1-to-1 relation between an MSC and its linearizations Joost-Pieter Katoen Theoretical Foundations of the UML 3/23 kin C M )
slide-8
SLIDE 8 Example p1 p2 p3 a b c d e msc Joost-Pieter Katoen Theoretical Foundations of the UML 4/23 e co
  • e
' ele ) = ! Cp , , Be , a) Ice ' )= ? ( Pap , , a)
slide-9
SLIDE 9 Example p1 p2 p3 a b c d e msc These pictures are formalized using partial orders. Joost-Pieter Katoen Theoretical Foundations of the UML 4/23
slide-10
SLIDE 10 Message Sequence Chart (MSC) (1) Definition An MSC M = (P, E, C, l, m, ) with: Joost-Pieter Katoen Theoretical Foundations of the UML 5/23
slide-11
SLIDE 11 Message Sequence Chart (MSC) (1) Definition An MSC M = (P, E, C, l, m, ) with: P, a finite set of processes {p1, p2, . . . , pn} Joost-Pieter Katoen Theoretical Foundations of the UML 5/23 O Pi Pz Pn G T u
slide-12
SLIDE 12 Message Sequence Chart (MSC) (1) Definition An MSC M = (P, E, C, l, m, ) with: P, a finite set of processes {p1, p2, . . . , pn} E, a finite set of events E =
  • p∈P
Ep = E? · ∪ E! Joost-Pieter Katoen Theoretical Foundations of the UML 5/23
  • vertically
horizontally
slide-13
SLIDE 13 Message Sequence Chart (MSC) (1) Definition An MSC M = (P, E, C, l, m, ) with: P, a finite set of processes {p1, p2, . . . , pn} E, a finite set of events E =
  • p∈P
Ep = E? · ∪ E! C, a finite set of message contents Joost-Pieter Katoen Theoretical Foundations of the UML 5/23
  • a
, b , c

I .
slide-14
SLIDE 14 Message Sequence Chart (MSC) (1) Definition An MSC M = (P, E, C, l, m, ) with: P, a finite set of processes {p1, p2, . . . , pn} E, a finite set of events E =
  • p∈P
Ep = E? · ∪ E! C, a finite set of message contents l : E → Act, a labelling function defined by: l(e) =
  • !(p, q, a)
if e ∈ Ep ∩ E! ?(p, q, a) if e ∈ Ep ∩ E? , for p = q ∈ P, a ∈ C Joost-Pieter Katoen Theoretical Foundations of the UML 5/23
slide-15
SLIDE 15 Message Sequence Chart (MSC) (2) Joost-Pieter Katoen Theoretical Foundations of the UML 6/23
slide-16
SLIDE 16 Message Sequence Chart (MSC) (2) Definition m : E! → E? a bijection (“matching function”), satisfying: m(e) = e′ ∧ l(e) = !(p, q, a) implies l(e′) = ?(q, p, a) (p = q, a ∈ C) Joost-Pieter Katoen Theoretical Foundations of the UML 6/23
  • e

µ.e

, meet
  • e
'
slide-17
SLIDE 17 Message Sequence Chart (MSC) (2) Definition m : E! → E? a bijection (“matching function”), satisfying: m(e) = e′ ∧ l(e) = !(p, q, a) implies l(e′) = ?(q, p, a) (p = q, a ∈ C) ⊆ E × E is a partial order (“visual order”) defined by: =
  • p∈P
<p <p is a total order = “top-to- bottom” order on process p ∪ {(e, m(e)) | e ∈ E!}
  • communication order <c
where for relation R, R∗ denotes its reflexive and transitive closure. Joost-Pieter Katoen Theoretical Foundations of the UML 6/23 ± C
  • *
slide-18
SLIDE 18 Example Joost-Pieter Katoen Theoretical Foundations of the UML 7/23 p a- r Eo
e , ez S m ( ez )=e , es # . ea m C es )=eg Hasse diagram < p i eco Cp es Cs i e , as ez eo

t Sr i eg Crea ez
  • 3
e , → to .
  • !
.
slide-19
SLIDE 19 Visual order can be misleading p1 p2 p3 a b c msc Joost-Pieter Katoen Theoretical Foundations of the UML 8/23
slide-20
SLIDE 20 Visual order can be misleading p1 p2 p3 a b c msc If message b takes much shorter than message a, then c might arrive at p1 before a. Joost-Pieter Katoen Theoretical Foundations of the UML 8/23 e ,
Eo f ez @

S

e⑨

eh ! Cpa , p , , a ) ! C pups , b) ? ( pg , Pz , b) ! ( pg , P , , c) 7 ! ( p , , Pz , C) G ! Cp , ,Pz , a )
slide-21
SLIDE 21 Visual order can be misleading p1 p2 p3 a b c msc If message b takes much shorter than message a, then c might arrive at p1 before a. In practice, e6 might occur before e2, but e2 <p1 e6 and thus e2 e6. This is misleading and called a race. Joost-Pieter Katoen Theoretical Foundations of the UML 8/23 ez
  • ez
E eb

EGO

I possible Ef
  • ccurs
before e ,
slide-22
SLIDE 22 What is a race? A race condition asserts a particular order of events will occur because
  • f the visual ordering (i.e., the partial order ) when, in practice, this
  • rder cannot be guaranteed to hold.
Joost-Pieter Katoen Theoretical Foundations of the UML 9/23
slide-23
SLIDE 23 What is a race? A race condition asserts a particular order of events will occur because
  • f the visual ordering (i.e., the partial order ) when, in practice, this
  • rder cannot be guaranteed to hold.
Q: When are race conditions possible and how to detect them? Joost-Pieter Katoen Theoretical Foundations of the UML 9/23
  • input
i formally define what algorithm
  • Msc
m is a race ? I
  • utput
: M has a race
  • r
not .
slide-24
SLIDE 24 Causal order Joost-Pieter Katoen Theoretical Foundations of the UML 10/23
  • defined
in a different way than £ : visual
  • rder
pot
  • f
the MSC definition .
slide-25
SLIDE 25 Causal order Main principles: Send events should happen before their matching receive events The ordering of events wrt. sends on same process is unaffected Receive events on a process sent from the same process are ordered as their sends Definition For MSC M = (P, E, C, l, m, ), relation ⊆ E × E is defined by: e e′ iff e′ = m(e) Joost-Pieter Katoen Theoretical Foundations of the UML 10/23 y similar as

visual
  • rder
  • O
e .
  • e
  • g
  • I
e ' e'
  • C
  • e
"

tea

ease '
slide-26
SLIDE 26 Causal order Main principles: Send events should happen before their matching receive events The ordering of events wrt. sends on same process is unaffected Receive events on a process sent from the same process are ordered as their sends Definition For MSC M = (P, E, C, l, m, ), relation ⊆ E × E is defined by: e e′ iff e′ = m(e)
  • r
e <p e′ and E! ∩ {e, e′} = ∅ Joost-Pieter Katoen Theoretical Foundations of the UML 10/23
a

:*

.
slide-27
SLIDE 27 p 9- r a e
  • c-
a hi ' Ce) b e '
  • E-
m ' ' ( e ' ) e ¢ e ° because thee is no process u such that m
  • ' (
e ) su m
  • '
Ce " ) as m
  • '
le ) and rn
  • ' (
e ' )
  • ccur
at different processes
slide-28
SLIDE 28 Causal order Main principles: Send events should happen before their matching receive events The ordering of events wrt. sends on same process is unaffected Receive events on a process sent from the same process are ordered as their sends Definition For MSC M = (P, E, C, l, m, ), relation ⊆ E × E is defined by: e e′ iff e′ = m(e)
  • r
e <p e′ and E! ∩ {e, e′} = ∅
  • r
e, e′ ∈ Ep ∩ E? and m−1(e) <q m−1(e′) Joost-Pieter Katoen Theoretical Foundations of the UML 10/23 p g r e.
  • m
" " y y
  • e

!

. m
  • ' let
TIP

slide-29
SLIDE 29 Causal order Main principles: Send events should happen before their matching receive events The ordering of events wrt. sends on same process is unaffected Receive events on a process sent from the same process are ordered as their sends Definition For MSC M = (P, E, C, l, m, ), relation ⊆ E × E is defined by: e e′ iff e′ = m(e)
  • r
e <p e′ and E! ∩ {e, e′} = ∅
  • r
e, e′ ∈ Ep ∩ E? and m−1(e) <q m−1(e′) ∗ is a partial order (referred to as causal order) in which events at the same process are not necessarily ordered. Joost-Pieter Katoen Theoretical Foundations of the UML 10/23

O

(

e . O
slide-30
SLIDE 30 Causal order: example Definition For MSC M = (P, E, C, l, m, ), relation ⊆ E × E is defined by: e e′ iff e′ = m(e)
  • r
e <p e′ and E! ∩ {e, e′} = ∅
  • r
e, e′ ∈ Ep ∩ E? and m−1(e) <q m−1(e′) Joost-Pieter Katoen Theoretical Foundations of the UML 11/23
slide-31
SLIDE 31 Causal order: example Definition For MSC M = (P, E, C, l, m, ), relation ⊆ E × E is defined by: e e′ iff e′ = m(e)
  • r
e <p e′ and E! ∩ {e, e′} = ∅
  • r
e, e′ ∈ Ep ∩ E? and m−1(e) <q m−1(e′) p1 p2 p3 a b c msc Joost-Pieter Katoen Theoretical Foundations of the UML 11/23
slide-32
SLIDE 32 Causal order: example Definition For MSC M = (P, E, C, l, m, ), relation ⊆ E × E is defined by: e e′ iff e′ = m(e)
  • r
e <p e′ and E! ∩ {e, e′} = ∅
  • r
e, e′ ∈ Ep ∩ E? and m−1(e) <q m−1(e′) p1 p2 p3 a b c msc Example Joost-Pieter Katoen Theoretical Foundations of the UML 11/23 ez e , g ea et er
slide-33
SLIDE 33 Causal order: example Definition For MSC M = (P, E, C, l, m, ), relation ⊆ E × E is defined by: e e′ iff e′ = m(e)
  • r
e <p e′ and E! ∩ {e, e′} = ∅
  • r
e, e′ ∈ Ep ∩ E? and m−1(e) <q m−1(e′) p1 p2 p3 a b c msc Example e1 e2, e3 e4, e5 e6, Joost-Pieter Katoen Theoretical Foundations of the UML 11/23
  • m
( e , ) = ez ez e , → e , a ez g es et es
slide-34
SLIDE 34 Causal order: example Definition For MSC M = (P, E, C, l, m, ), relation ⊆ E × E is defined by: e e′ iff e′ = m(e)
  • r
e <p e′ and E! ∩ {e, e′} = ∅
  • r
e, e′ ∈ Ep ∩ E? and m−1(e) <q m−1(e′) p1 p2 p3 a b c msc Example e1 e2, e3 e4, e5 e6, e1 e3, e4 e5, Joost-Pieter Katoen Theoretical Foundations of the UML 11/23
ez
  • e ,
Eg Cpg e5 ez
  • es
EG er { eases ) n E ! -40 es aces er
  • X
② ②
slide-35
SLIDE 35 Causal order: example Definition For MSC M = (P, E, C, l, m, ), relation ⊆ E × E is defined by: e e′ iff e′ = m(e)
  • r
e <p e′ and E! ∩ {e, e′} = ∅
  • r
e, e′ ∈ Ep ∩ E? and m−1(e) <q m−1(e′) p1 p2 p3 a b c msc Example e1 e2, e3 e4, e5 e6, e1 e3, e4 e5, not (e2 e6) Joost-Pieter Katoen Theoretical Foundations of the UML 11/23

O

slide-36
SLIDE 36 Races Definition MSC M contains a race if for some e, e′ ∈ E? and process p: e <p e′ but not (e ∗ e′) where ∗ ⊆ E × E is the reflexive and transitive closure of . As relation ∗ contains at most all orderings in , the MSC M has a race whenever ⊆ ∗. Joost-Pieter Katoen Theoretical Foundations of the UML 12/23 .
  • O
O voi

÷

!

slide-37
SLIDE 37 Race: example p1 p2 p3 a b c msc Joost-Pieter Katoen Theoretical Foundations of the UML 13/23
slide-38
SLIDE 38 Race: example p1 p2 p3 a b c msc Visual order versus causal order 1 e1 e2, e3 e4, e5 e6, e1 e3, e4 e5, e2 e6 2 e1 e2, e3 e4, e5 e6, e1 e3, e4 e5, not (e2 e6) As ⊆ ∗, this MSC contains a race. Joost-Pieter Katoen Theoretical Foundations of the UML 13/23

e

: :&

  • O
slide-39
SLIDE 39 Other examples On the black board. Joost-Pieter Katoen Theoretical Foundations of the UML 14/23
slide-40
SLIDE 40 p s r
  • a
MSC has a race 7

702

a : b 3

34

y as 6 c C r g 45
  • 4
a 2 I : a t 2 I b
  • Kg
  • scab
because 2

sp

6 not za 6 t
  • p
E r a z
  • >
2 MSC has no b 4 s 3 race .
  • C
6 a t K : n K2 , ska ,

546

,

245

,

1K

3,3

KG

= I visual
  • rder
slide-41
SLIDE 41 Why are races problematic? Recall: MSC M has a race if ⊆ ∗ or equivalently: ∃e, e′ ∈ E? . (e <p e′ and e ∗ e′) Whenever ⊆ ∗, implementations based on <p may cause problems: 1 unspecified message reception a process receives a message which by the MSC is not possible 2 deadlocks a process blocking on receipt of an unexpected message may block
  • thers too
3 message loss unexpectedly received messages may be ignored 4 exploiting wrong message content Joost-Pieter Katoen Theoretical Foundations of the UML 15/23

{

  • ÷
: :
slide-42
SLIDE 42 Checking whether an MSC has a race 1for digraphs without negative cycles. Joost-Pieter Katoen Theoretical Foundations of the UML 16/23 Tortosa
slide-43
SLIDE 43 Checking whether an MSC has a race MSC M has a race if ⊆ ∗ How to check whether MSC M has a race? compute ∗ and check whether ⊆ ∗ transitive closure ∗ is computed using Floyd-Warshall’s algorithm algorithm for finding shortest paths in a weighted digraph with positive or negative edge weights1 easily adapted for computing the transitive closure of digraphs worst-case time complexity O(|E|3) by using some specifics of MSC, this is reduced to O(|E|2) So: race checking can be done quadratically in the number of events 1for digraphs without negative cycles. Joost-Pieter Katoen Theoretical Foundations of the UML 16/23

I

  • ]
no

es O

relation

set
  • f
events in MSC M
slide-44
SLIDE 44 Computing ∗: Warshall’s algorithm Algorithm compute ∗
  • Warshall’s algorithm
and compare with Warshall’s algorithm: input: R ⊆ X × X where X is a set
  • utput:
R∗ Joost-Pieter Katoen Theoretical Foundations of the UML 17/23 # X = E for Msas O
slide-45
SLIDE 45 Computing ∗: Warshall’s algorithm Algorithm compute ∗
  • Warshall’s algorithm
and compare with Warshall’s algorithm: input: R ⊆ X × X where X is a set
  • utput:
R∗ Idea: Consider R and R∗ as directed graphs There is an edge x ⇒ y in R∗ iff there is a (possibly empty) sequence x = x0 → x1 → x2 → . . . → xn = y in R (our setting: X = E, R = , R∗ = ∗) Joost-Pieter Katoen Theoretical Foundations of the UML 17/23
  • O
  • =
slide-46
SLIDE 46 Warshall’s algorithm: preliminaries Joost-Pieter Katoen Theoretical Foundations of the UML 18/23
slide-47
SLIDE 47 Warshall’s algorithm: preliminaries assume: graph vertices are numbered {1, 2, . . . , n} where n = |E| Joost-Pieter Katoen Theoretical Foundations of the UML 18/23 = 1×1 R X={ x , , .
  • ,xu )
R={ C x , ,xa ) , Cska ) , ( Xz ,Xs ) )
  • graph
( r ) :
slide-48
SLIDE 48 Warshall’s algorithm: preliminaries assume: graph vertices are numbered {1, 2, . . . , n} where n = |E| for j ∈ {1, . . . , n+1} define relation j = ⇒ as follows: x j = ⇒ y iff ∃ path in R from x to y such that all vertices
  • n the path (= x, y) have a smaller number than j
Joost-Pieter Katoen Theoretical Foundations of the UML 18/23 ④ FEE

.to

number a j x

Is y

slide-49
SLIDE 49 Warshall’s algorithm: preliminaries assume: graph vertices are numbered {1, 2, . . . , n} where n = |E| for j ∈ {1, . . . , n+1} define relation j = ⇒ as follows: x j = ⇒ y iff ∃ path in R from x to y such that all vertices
  • n the path (= x, y) have a smaller number than j
Then: (1) x = ⇒ y iff x n+1 = ⇒ y (2) x 1 = ⇒ y iff x = y or x y (3) x y+1 = ⇒ z iff x y = ⇒ z or x y = ⇒ y y = ⇒ z Joost-Pieter Katoen Theoretical Foundations of the UML 18/23
  • \
ntn
  • X
  • sy
O I initial isatin
  • by
indnetinaj
  • stat
ja x y
slide-50
SLIDE 50 Warshall’s algorithm: preliminaries assume: graph vertices are numbered {1, 2, . . . , n} where n = |E| for j ∈ {1, . . . , n+1} define relation j = ⇒ as follows: x j = ⇒ y iff ∃ path in R from x to y such that all vertices
  • n the path (= x, y) have a smaller number than j
Then: (1) x = ⇒ y iff x n+1 = ⇒ y (2) x 1 = ⇒ y iff x = y or x y (3) x y+1 = ⇒ z iff x y = ⇒ z or x y = ⇒ y y = ⇒ z Algorithm: determine the relations 1 = ⇒, . . . , n = ⇒, n+1 = ⇒ iteratively using properties (2) + (3); Joost-Pieter Katoen Theoretical Foundations of the UML 18/23 ( , Y ) ER *
  • f
termination Condition
slide-51
SLIDE 51 Warshall’s algorithm: preliminaries assume: graph vertices are numbered {1, 2, . . . , n} where n = |E| for j ∈ {1, . . . , n+1} define relation j = ⇒ as follows: x j = ⇒ y iff ∃ path in R from x to y such that all vertices
  • n the path (= x, y) have a smaller number than j
Then: (1) x = ⇒ y iff x n+1 = ⇒ y (2) x 1 = ⇒ y iff x = y or x y (3) x y+1 = ⇒ z iff x y = ⇒ z or x y = ⇒ y y = ⇒ z Algorithm: determine the relations 1 = ⇒, . . . , n = ⇒, n+1 = ⇒ iteratively using properties (2) + (3); Result is then given by (1). Store i = ⇒ in a boolean matrix C of cardinality |E| × |E| Joost-Pieter Katoen Theoretical Foundations of the UML 18/23 O
slide-52
SLIDE 52 Warshall’s algorithm: preliminaries assume: graph vertices are numbered {1, 2, . . . , n} where n = |E| for j ∈ {1, . . . , n+1} define relation j = ⇒ as follows: x j = ⇒ y iff ∃ path in R from x to y such that all vertices
  • n the path (= x, y) have a smaller number than j
Then: (1) x = ⇒ y iff x n+1 = ⇒ y (2) x 1 = ⇒ y iff x = y or x y (3) x y+1 = ⇒ z iff x y = ⇒ z or x y = ⇒ y y = ⇒ z Algorithm: determine the relations 1 = ⇒, . . . , n = ⇒, n+1 = ⇒ iteratively using properties (2) + (3); Result is then given by (1). Store i = ⇒ in a boolean matrix C of cardinality |E| × |E| Postcondition: C[x, y] = true iff (x, y) ∈ R∗ Precondition: ∀x, y ∈ X . C[x, y] = false Joost-Pieter Katoen Theoretical Foundations of the UML 18/23 termination initial isatin loop .
slide-53
SLIDE 53 Warshall’s algorithm /* first compute x 1 = ⇒ y */ for x := 1 to n do for y := 1 to n do C[x, y] := (x = y or (x, y) ∈ R
  • xy
) /* loop invariant: after the j-th iteration of */ /* outermost loop it holds: C[x, y] = true iff x j+1 = ⇒ y */ for y := 1 to n do for x := 1 to n do if C[x, y] then for z := 1 to n do if C[y, z] then C[x, z] := true Joost-Pieter Katoen Theoretical Foundations of the UML 19/23
  • }
init axon i .
Is . . . . 2 .
  • s
. { g
  • I
it y

}

loop y ⇒ z
  • x ?E→z
slide-54
SLIDE 54 Correctness and complexity Lemma: correctness After j iterations: x j+1 = ⇒ y iff C[x, y] = true. Proof. if: trivial; only if: by induction on j. Joost-Pieter Katoen Theoretical Foundations of the UML 20/23
slide-55
SLIDE 55

Claim

: after j iterations

(

for any
  • EjEn

)

: jti k m implies CEk,mJ=7

Proof

:

by

induction
  • n
j . 1) base case : j=o i it follows from the initial isatin jtr 2) ind . step : let j 3
  • and
assume he m
  • a)
if C Ek , m ] , done

k¥m

b) assume C Ebm ) =
  • .
Then

by

ind . hyp . , it follows k ¥ m . But since he m iff k # m
  • r
k # j m Cby Cs )) it follows k # j m . Thus C Eksj] = tune and C Ejsm ] = tune Thes

deny

the j
  • th
iteration Cham ) is set to true DX
slide-56
SLIDE 56 Correctness and complexity Lemma: correctness After j iterations: x j+1 = ⇒ y iff C[x, y] = true. Proof. if: trivial; only if: by induction on j. Complexity Worst-case time complexity of Warshall’s algorithm : O(n3) with n = |X| Proof. follows from the fact that there is a triple-nested loop of which each loop has at most n iterations. Joost-Pieter Katoen Theoretical Foundations of the UML 20/23
slide-57
SLIDE 57 Efficiency improvement [Alur et al. ’96] Warshall’s algorithm computes R∗ for every binary relation R ⊆ X × X. Joost-Pieter Katoen Theoretical Foundations of the UML 21/23 T arbitrary
slide-58
SLIDE 58 Efficiency improvement [Alur et al. ’96] Warshall’s algorithm computes R∗ for every binary relation R ⊆ X × X. Recall: our interest is in determining R∗ for R = Joost-Pieter Katoen Theoretical Foundations of the UML 21/23
  • O
slide-59
SLIDE 59 Efficiency improvement [Alur et al. ’96] Warshall’s algorithm computes R∗ for every binary relation R ⊆ X × X. Recall: our interest is in determining R∗ for R = Using some properties of , the complexity can be improved. Joost-Pieter Katoen Theoretical Foundations of the UML 21/23 O

Tin

slide-60
SLIDE 60 Efficiency improvement [Alur et al. ’96] Warshall’s algorithm computes R∗ for every binary relation R ⊆ X × X. Recall: our interest is in determining R∗ for R = Using some properties of , the complexity can be improved. Exploit that for : Joost-Pieter Katoen Theoretical Foundations of the UML 21/23
slide-61
SLIDE 61 Efficiency improvement [Alur et al. ’96] Warshall’s algorithm computes R∗ for every binary relation R ⊆ X × X. Recall: our interest is in determining R∗ for R = Using some properties of , the complexity can be improved. Exploit that for : 1 is acyclic (as it is a partial order) 2 the number of immediate predecessors of e ∈ E under is at most two (why?) Note that e is an immediate predecessor of e′ (under ) if: e e′ and ¬(∃e′′ / ∈ {e, e′}. e e′′ ∧ e′′ e′) Joost-Pieter Katoen Theoretical Foundations of the UML 21/23 e " ⑧ → e' too
  • fo
e
slide-62
SLIDE 62 Efficiency improvement [Alur et al. ’96] The main loop of Warshall’s algorithm: for e := 1 to n do for e′ := 1 to n do if C[e′, e] then for e′′ := 1 to n do if C[e, e′′] then C[e′, e′′] := true Joost-Pieter Katoen Theoretical Foundations of the UML 22/23 e " e ' e
  • e
"

[

c :

[

e ' . e Cee 're " I
slide-63
SLIDE 63 Efficiency improvement [Alur et al. ’96] The main loop of Warshall’s algorithm: for e := 1 to n do for e′ := 1 to n do if C[e′, e] then for e′′ := 1 to n do if C[e, e′′] then C[e′, e′′] := true The main loop of Alur et. al.’s algorithm for detecting races in MSCs: for e := 1 to n do for e′ := e − 1 downto 1 do if (not C[e′, e] and e′ e) then C[e′, e] := true for e′′ := 1 to e′ − 1 do if C[e′′, e′] then C[e′′, e] := true Joost-Pieter Katoen Theoretical Foundations of the UML 22/23

I

  • ur
e " e ' e eh

{

any e .

)

e
slide-64
SLIDE 64 Detecting races in MSCs Theorem Let M be an MSC with set E of events and n = |E|. Checking whether M has a race can be done in O(n2). Proof. Joost-Pieter Katoen Theoretical Foundations of the UML 23/23
slide-65
SLIDE 65 Detecting races in MSCs Theorem Let M be an MSC with set E of events and n = |E|. Checking whether M has a race can be done in O(n2). Proof. Since is acyclic, we number the events such that the numbering defines a total
  • rder that is consistent with visual order . This can be done in O(n) using a
standard topological sort. Joost-Pieter Katoen Theoretical Foundations of the UML 23/23
slide-66
SLIDE 66 Detecting races in MSCs Theorem Let M be an MSC with set E of events and n = |E|. Checking whether M has a race can be done in O(n2). Proof. Since is acyclic, we number the events such that the numbering defines a total
  • rder that is consistent with visual order . This can be done in O(n) using a
standard topological sort. Then observe that the innermost loop: for e′′ := 1 to e′ − 1 do if C[e′′, e′] then C[e′′, e] := true
  • f the triple-nested main loop is executed for (e, e′) only if e′ is an immediate
predecessor of e under . Joost-Pieter Katoen Theoretical Foundations of the UML 23/23 "
slide-67
SLIDE 67 Detecting races in MSCs Theorem Let M be an MSC with set E of events and n = |E|. Checking whether M has a race can be done in O(n2). Proof. Since is acyclic, we number the events such that the numbering defines a total
  • rder that is consistent with visual order . This can be done in O(n) using a
standard topological sort. Then observe that the innermost loop: for e′′ := 1 to e′ − 1 do if C[e′′, e′] then C[e′′, e] := true
  • f the triple-nested main loop is executed for (e, e′) only if e′ is an immediate
predecessor of e under . As for MSCs, an event can have at most two immediate predecessors, the innermost two loop is executed at most 2 · n times in total. Joost-Pieter Katoen Theoretical Foundations of the UML 23/23
slide-68
SLIDE 68 Detecting races in MSCs Theorem Let M be an MSC with set E of events and n = |E|. Checking whether M has a race can be done in O(n2). Proof. Since is acyclic, we number the events such that the numbering defines a total
  • rder that is consistent with visual order . This can be done in O(n) using a
standard topological sort. Then observe that the innermost loop: for e′′ := 1 to e′ − 1 do if C[e′′, e′] then C[e′′, e] := true
  • f the triple-nested main loop is executed for (e, e′) only if e′ is an immediate
predecessor of e under . As for MSCs, an event can have at most two immediate predecessors, the innermost two loop is executed at most 2 · n times in total. This yields a total worst-case time complexity of n2+2·n. Joost-Pieter Katoen Theoretical Foundations of the UML 23/23