Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint...

25
Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania

Transcript of Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint...

Page 1: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Shared Variables Interaction Diagrams

Radu GrosuState University of New York at Stony

Brook

joint work with

Rajeev AlurUniversity of Pennsylvania

Page 2: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Motivation

• Scenario-based specifications are very popular in concurrent systems development:

– intuitive description of design requirements,

– intuitive presentation of system executions,

– compact presentation test sequences.

Page 3: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Fact

• Concurrent systems are usually constructed around one of the following communication models:

– Shared variables

– Message passing

Page 4: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Message Passing

• standardized notation in form of MSCs (UML-SDs)

• precise semantics subjected to analysis,

• algorithms and tools (race conditions, timing conflicts…)

Page 5: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Shared Variables?

No formal notation so far!

• but plenty informal diagrams

Page 6: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

In This Work

• Define Shared Variables Interaction Diagrams (SVID):

– introduce the notion of consistent SVID,

– analyze complexity of consistency checking:

•many-to-many communication

• one-to-many communication

• Define refinement notion between SVIDs:– intuitive syntactic refinement steps,

– analyze complexity of refinement checking:

•many-to-many communication

• point-to-point communication

Page 7: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Peterson Mutual Exclusion Protocol

p1

ini

idle

f1:=F

f1:=T

t :=2

f1:=F

p2

ini

idle

reqCS reqCS

f2:=F

f2:=T

t :=1

t t

inCS f1

idle reqCS

p1

ini

idle

reqCS

f1:=F

f1:=T

t :=2

f2

inCS

f1:=F

p2

ini

idle

f2:=F

idle idle

f1= T: p1 wants to enter critical section

f2= T: p2 wants to enter critical section

t = 1: p1 has priority

Page 8: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

idle

t

reqCS reqCS

f1:=T

t :=2

idle

f1:=F

ini

f1:=F

ini

f2:=F

f2:=T

t :=1

t

inCS f1

idle reqCS

Processes p1 p2

p1.Xr = {f2} - read variables

p1.Xs = {t} - write shared variables

p1.Xe = {f1} - write exclusive variables

p1.Xw = {t,f1} - write variables

p1.X = {t,f1,f2} - all variables

Page 9: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Vertices

idle reqCS

p2

idle

ini

idle

ini

reqCS reqCS

inCS

f1:=F

f1:=T

t :=2

f1:=F

f2:=F

f2:=T

t :=1

t t

f1

p1

v14

v13

v12

v11

v24

v23

v22

v21

Page 10: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Vertices

idle reqCS

p2

idle

ini

idle

ini

reqCS reqCS

inCS

f2:=F

f2:=T

t :=1

f1:=F

f1:=T

t :=2

f1:=F

t t

f1

p1

v14

v13

v12

v11

v24

v23

v22

v21

v1i.p = p1

p1.V = {v11,v12,v13,v14}

V = p1.V p2.V

< = <p1 <p2

linear

order=

timeflow

<p

1

Page 11: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Atomic Update Boxes

idle reqCS

p1 p2

idle

ini

idle

ini

reqCS reqCS

inCS

f1:=F

f1:=T t :=2

f1:=F

f2:=F

f2:=T

t :=1

t t

f1

v12

v13

read variables

(t)

assignment

(state)

explicit write variables (t,f1)

implicit write

variables (f1)

Page 12: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Read Edges

p1

ini

idle

f1:=F

f1:=T

t :=2

f1:=F

p2

ini

idle

reqCS reqCS

f2:=F

f2:=T

t :=1

t t

inCS f1

idle reqCS

no intervening

vertex writes t

v13

v12

v23

v22

v24

v12 v22 v13 v23 v24 v12 v22 v23 v13 v24 v12 v22 v23 v24 v13

partial orderamong

vertices

Page 13: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Consistent SVID

There is a sequence v1 v2 … vn that:

(1) is consistent with time order <

(2) is consistent with read order E

(3) respects most recent updates.

Page 14: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Inconsistent SVID

p1

three

o1:=F o2

two

o1:=T

one

p1

three

o2:=F o1

two

o2:=T

one

v11 v21

v12 v22

v11

v21

v12

v22

v11

v21

v22

v12

Page 15: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Checking Consistency

One-to-many communication (write exclusive):

- Solved in linear time.

- Reduces to finding a cycle in a graph.

Many-to-many communication (write shared):

- In general NP complete.

- Resolving implicit dependencies -> backtrack.

Page 16: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Refinement

When does I refine S written I S?

- Interested in a refinement notion that has a syntactic counterpart that guides users.

Three simple ways to refine an SVID:

- By moving arrows and adding empty boxes.

- By splitting vertices.- By splitting processes.

Page 17: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Moving Arrows & Adding Empty Boxes

p1

p2

idle

ini

idle

f1:=F

f1:=T

t :=2

f1:=F

ini

reqCS reqCS

f2:=F

f2:=T

t :=1

t t

inCS f1

idle reqCS

p1

p2

idle

ini

idle

f1:=F

f1:=T

t :=2

f1:=F

ini

reqCS reqCS

f2:=F

f2:=T

t :=1

t t

inCS f1

idle reqCS

Page 18: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

p1

p2

idle

ini

idle

f1:=F

f1:=T

t :=2

f1:=F

ini

reqCS reqCS

f2:=F

f2:=T

t :=1

t t

inCS f1

idle reqCS

p1

p2

idle

ini

idle

f1:=F

f1:=T

t :=2

f1:=F

ini

reqCS reqCS

f2:=F

f2:=T

t :=1

t t

inCS f1

idle reqCS

Splitting Vertices

f1:=T

t :=2

f2:=T

t :=1

Page 19: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Splitting Processes

p1

p2

idle

ini

idle

f1:=F

f1:=F

ini

reqCS reqCS

f2:=F

t t

inCS f1

idle reqCS

f1:=T

t :=2

f2:=T

t :=1

p1

p2

idle

ini

idle

f1:=F

f1:=F

ini

reqCS reqCS

f2:=F

t t

inCS f1

idle reqCS

f1:=T

t :=2

f2:=T

t :=1

p2

idle

ini

reqCS

f2:=F

t

f1

reqCS

f2:=T

p1

t

ini

idle

f1:=F

f1:=F

reqCS

t

inCS

idle

f1:=T

t :=2

t :=1

Page 20: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Refinement

When does I refine S written I S?

- Variables: S.X = I.X

- Processes: p.X q.X = {} or p.X q.X

- Boxes: there is a surjective map r form the vertices I to the vertices of S that preserves the variables.

- Dependency: The specification partial order (S.E S.<) is included in the image r(I.E I.<).

Page 21: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Checking Refinement

p1

p2

idle

ini

idle

f1:=F

f1:=F

ini

reqCS reqCS

f2:=F

t t

inCS f1

idle reqCS

f1:=T

t :=2 f2:=T

t :=1

p2

idle

ini

reqCS

f2:=F

t

f1

reqCS

f2:=T

p1

t

ini

idle

f1:=F

f1:=F

reqCS

t

inCS

idle

f1:=T

t :=2

t :=1

Page 22: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Checking Refinement

Point-to-point communication:

- Solved in O(|V|3).

- Reduces to computing the transitive closure.

Many-to-many communication:

- In general NP complete.

- Guessing the vertex map -> backtrack.

Page 23: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Deadlock for Dining Philosophers

p1

ini

tstR

f1:=F

tstL

tstL

f1:=T f1

f3

p3

ini

tstR

f3:=F

tstL

tstL

f3:=T f3

f2

p2

ini

tstR

f2:=F

tstL

tstL

f2:=T f2

f1

Page 24: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Deadlock for Dining Philosophers

p1

ini

tstR

tstL

tstL

f3

ini

tstR

tstL

tstL

p2

ini

tstR

tstL

tstL

f1

ini

tstR

tstL

tstL

f2

ini

tstR

tstL

tstL

p3

ini

tstR

tstL

tstL

set(F) set(F) set(F)

get get get

val(F) val(F)set(T)

val(F)set(T) set(T)

get

val(T)

get

val(T)get

val(T)

Page 25: Shared Variables Interaction Diagrams Radu Grosu State University of New York at Stony Brook joint work with Rajeev Alur University of Pennsylvania.

Wrap Up

• Defined Shared Variables Interaction Diagrams (SVID):

– introduced the notion of consistent SVID,

– analyzed complexity of consistency checking:

•many-to-many communication

• one-to-many communication

• Defined refinement notion between SVIDs:– intuitive syntactic refinement steps,

– analyzed complexity of refinement checking:

•many-to-many communication

• point-to-point communication