Top Banner
Modeling Software Systems Lecture 2 Book: Chapter 4
41

Modeling Software Systems Lecture 2 Book: Chapter 4.

Mar 28, 2015

Download

Documents

Maria Vega
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Modeling Software Systems Lecture 2 Book: Chapter 4.

Modeling Software Systems

Lecture 2Book: Chapter 4

Page 2: Modeling Software Systems Lecture 2 Book: Chapter 4.

Systems of interest

Sequential systems. Concurrent systems.

1. Distributive systems.2. Reactive systems.3. Embedded systems

(software + hardware).

Page 3: Modeling Software Systems Lecture 2 Book: Chapter 4.

Sequential systems.

Perform some computational task. Have some initial condition, e.g.,

0≤i≤n A[i]≥0, A[i] integer. Have some final assertion, e.g.,

0≤i≤n-1 A[i]<A[i+1].(What is the problem with this spec?)

Are supposed to terminate.

Page 4: Modeling Software Systems Lecture 2 Book: Chapter 4.

Concurrent Systems

Involve several computation agents.Termination may indicate an abnormal

event (interrupt, strike).May exploit diverse computational

power.May involve remote components.May interact with users (Reactive).May involve hardware components

(Embedded).

Page 5: Modeling Software Systems Lecture 2 Book: Chapter 4.

Problems in modeling systems Representing concurrency:

- Allow one transition at a time.- Allow coinciding transitions.- Allow a partial order between events.

Granularity of transitions. Execution model (linear, branching). Global or local states.

Page 6: Modeling Software Systems Lecture 2 Book: Chapter 4.

Modeling

V={v0,v1,v2, …} - a set of variables, over some domain.

p(v0, v1, …, vn) - a parametrized assertion, e.g., v0=v1+v2/\v3>v4.

A state is an assignment of values to the program variables. For example: s=<v0=1,v2=3,v3=7,…,v18=2>

p(s) is p under the assignment s.

Page 7: Modeling Software Systems Lecture 2 Book: Chapter 4.

State space

The state space of a program is the set of all possible states for it.

For example, if V={a, b, c} and the variables are over the naturals, then the state space includes: <a=0,b=0,c=0>,<a=1,b=0,c=0>, <a=1,b=1,c=0>,<a=932,b=5609,c=6658>…

Page 8: Modeling Software Systems Lecture 2 Book: Chapter 4.

Atomic Transitions

Each atomic transition represents a small peace of code such that no smaller peace of code is observable.

Is a:=a+1 atomic? In some systems, e.g., when a is a

register and the transition is executed using an inc command.

Page 9: Modeling Software Systems Lecture 2 Book: Chapter 4.

Non atomicity

Execute the following when x=0 in two concurrent processes:

P1:a=a+1 P2:a=a+1 Result: a=2. Is this always the

case?

Consider the actual translation:

P1:load R1,a inc R1 store R1,aP2:load R2,a inc R2 store R2,a a may be also 1.

Page 10: Modeling Software Systems Lecture 2 Book: Chapter 4.

Representing transitions

Each transition has two parts: The enabling condition: a predicate. The transformation: a multiple assignment.

For example:a>b (c,d):=(d,c)This transition can be executed in states where a>b. The result of executing it isswitching the value of c with d.

Page 11: Modeling Software Systems Lecture 2 Book: Chapter 4.

Initial condition

A predicate p. The program

can start from states s such that p(s) holds.

For example:p(s)=a>b /\ b>c.

Page 12: Modeling Software Systems Lecture 2 Book: Chapter 4.

A transition system

A (finite) set of variables V over some domain(s).

A set of states . A (finite) set of transitions T, each

transition et has an enabling condition e, and a transformation t.

An initial condition p.

Page 13: Modeling Software Systems Lecture 2 Book: Chapter 4.

Example

V={a, b, c, d, e}. : all assignments of natural

numbers for variables in V. T={c>0(c,e):=(c-1,e+1),

d>0(d,e):=(d-1,e+1)} p: c=a /\ d=b /\ e=0 What does this transition relation

do?

Page 14: Modeling Software Systems Lecture 2 Book: Chapter 4.

The interleaving model

An execution is a finite or infinite sequence of states s0, s1, s2, …

The initial state satisfies the initial condition, I.e., p(s0).

Moving from one state si to si+1 is by executing a transition et: e(si), I.e., si satisfies e. si+1 is obtained by applying t to si.

Page 15: Modeling Software Systems Lecture 2 Book: Chapter 4.

Example:

s0=<a=2, b=1, c=2, d=1, e=0> (satisfies the initial condition)

s1=<a=2, b=1, c=1, d=1, e=1>(first transition executed)

s2=<a=2, b=1, c=1, d=0, e=2>(second transition executed)

s3=<a=2, b=1 ,c=0, d=0, e=3>(first transition executed again)

Page 16: Modeling Software Systems Lecture 2 Book: Chapter 4.

Temporal Logic (informal) First order logic or

propositional assertions describe a state.

Modalities: <>p means p will happen eventually.

[]p means p will happen always.

p

p pppppp

Page 17: Modeling Software Systems Lecture 2 Book: Chapter 4.

More temporal logic

We can construct more complicated formulas:

[]<>p -- It is always the case that p will happen again in the future (infinitely often).

<>p /\ <>q -- Both p and q will happen in the future, the order between them not determined.

The property must hold for all the executions of the program.

Page 18: Modeling Software Systems Lecture 2 Book: Chapter 4.

L0:While True do NC0:wait(Turn=0); CR0:Turn=1endwhile ||L1:While True do NC1:wait(Turn=1); CR1:Turn=0endwhile

T0:PC0=L0PC0:=NC0T1:PC0=NC0/\Turn=0 PC0:=CR0T2:PC0=CR0 (PC0,Turn):=(L0,1)T3:PC1=L1PC1=NC1T4:PC1=NC1/\Turn=1 PC1:=CR1T5:PC1=CR1 (PC1,Turn):=(L1,0)

Initially: PC0=L0/\PC1=L1

The transitions

Page 19: Modeling Software Systems Lecture 2 Book: Chapter 4.

The state space

Turn=0L0,L1

Turn=0L0,NC1

Turn=0NC0,L1

Turn=0CR0,NC1

Turn=0NC0,NC1

Turn=0CR0,L1

Turn=1L0,CR1

Turn=1NC0,CR1

Turn=1L0,NC1

Turn=1NC0,NC1

Turn=1NC0,L1

Turn=1L0,L1

Page 20: Modeling Software Systems Lecture 2 Book: Chapter 4.

[]¬(PC0=CR0/\PC1=CR1)

Turn=0L0,L1

Turn=0L0,NC1

Turn=0NC0,L1

Turn=0CR0,NC1

Turn=0NC0,NC1

Turn=0CR0,L1

Turn=1L0,CR1

Turn=1NC0,CR1

Turn=1L0,NC1

Turn=1NC0,NC1

Turn=1NC0,L1

Turn=1L0,L1

Page 21: Modeling Software Systems Lecture 2 Book: Chapter 4.

[](Turn=0--><>Turn=1)

Turn=0L0,L1

Turn=0L0,NC1

Turn=0NC0,L1

Turn=0CR0,NC1

Turn=0NC0,NC1

Turn=0CR0,L1

Turn=1L0,CR1

Turn=1NC0,CR1

Turn=1L0,NC1

Turn=1NC0,NC1

Turn=1NC0,L1

Turn=1L0,L1

Page 22: Modeling Software Systems Lecture 2 Book: Chapter 4.

Interleaving semantics

Turn=0L0,L1

Turn=0L0,NC1

Turn=0CR0,NC1

Turn=0NC0,NC1

Turn=1L0,CR1

Turn=1L0,NC1

Page 23: Modeling Software Systems Lecture 2 Book: Chapter 4.

Interleaving semantics

Turn=0L0,L1

Turn=0L0,NC1

Turn=0CR0,NC1

Turn=0NC0,NC1

Turn=1L0,CR1

Turn=1L0,NC1

Turn=0L0,L1

Turn=0L0,NC1

Page 24: Modeling Software Systems Lecture 2 Book: Chapter 4.

An unfoldingTurn=0L0,L1

Turn=0L0,NC1

Turn=0NC0,L1

Turn=0CR0,NC1

Turn=0NC0,NC1

Turn=0CR0,L1

Turn=1L0,NC1

Turn=0NC0,NC1

Turn=0CR0,NC1

Turn=0CR0,NC1

Page 25: Modeling Software Systems Lecture 2 Book: Chapter 4.

Partial Order Semantics Sometimes called “real concurrency”. There is no total order between events. More intuitive. Closer to the actual behavior of

the system. More difficult to analyze. Less verification results. Natural transformation between models. Partial order: (S , <), where < is

Reflexive: x<y /\ y<z x<z. Antisymmetric: for no x, y, x<y /\ y>x. Antireflexive: for no x, x<x.

Page 26: Modeling Software Systems Lecture 2 Book: Chapter 4.

Bank Example

Two branches, initially $1M each. In one branch: deposit, $2M. In another branch: robbery. How to model the system?

Page 27: Modeling Software Systems Lecture 2 Book: Chapter 4.

Global state space

$1M, $1M

$3M, $0M

$1M, $0M$3M, $1M

deposit

deposit

robbery

robbery

Page 28: Modeling Software Systems Lecture 2 Book: Chapter 4.

Should we invest in this bank?

$1M, $1M

$3M, $0M

$1M, $0M$3M, $1M

deposit

deposit

robbery

robbery

Invest!

Do not Invest!

Invest!

Page 29: Modeling Software Systems Lecture 2 Book: Chapter 4.

Partial Order Description

$1M

$3M $0M

$1M

deposit

robbery

Page 30: Modeling Software Systems Lecture 2 Book: Chapter 4.

Constructing global states

$1M

$3M $0M

$1M

deposit

robbery

Page 31: Modeling Software Systems Lecture 2 Book: Chapter 4.

Modeling with partial orders

m0:x:=x+1

m1:ch!x n1:y:=y+z

n0:ch?z

P1 P2

m0

n0

n0

m0

n1

n1m0

m1

m1

pc1=m0,x=0

pc1=m0,x=2

pc1=m0,x=1

pc1=m1,x=1

pc1=m1,x=2

pc2=n0,y=0,z=0

pc2=n0,y=1,z=1

pc2=n1,y=0,z=1

pc2=n1,y=1,z=2

Page 32: Modeling Software Systems Lecture 2 Book: Chapter 4.

Linearizations

m0

n0

n0

m0

n1

n1m0

m1

m1

pc1=m0,x=0

pc1=m0,x=2

pc1=m0,x=1

pc1=m1,x=1

pc1=m1,x=2

pc2=n0,y=0,z=0

pc2=n0,y=1,z=1

pc2=n1,y=0,z=1

pc2=n1,y=1,z=2

pc1=m0,x=0,pc2=n0,y=0,z=0

pc1=m1,x=2,pc2=n0,y=1,z=1

pc1=m1,x=2,pc2=n1,y=0,z=1

pc1=m0,x=1,pc2=n1,y=0,z=1

pc1=m1,x=1,pc2=n0,y=0,z=0

pc1=m0,x=2,pc2=n1,y=1,z=2

Page 33: Modeling Software Systems Lecture 2 Book: Chapter 4.

Linearizations

m0

n0

n0

m0

n1

n1m0

m1

m1

pc1=m0,x=0

pc1=m0,x=2

pc1=m0,x=1

pc1=m1,x=1

pc1=m1,x=2

pc2=n0,y=0,z=0

pc2=n0,y=1,z=1

pc2=n1,y=0,z=1

pc2=n1,y=1,z=2

pc1=m0,x=0,pc2=n0,y=0,z=0

pc1=m1,x=2,pc2=n0,y=1,z=1

pc1=m0,x=1,pc2=n0,y=1,z=1

pc1=m0,x=1,pc2=n1,y=0,z=1

pc1=m1,x=1,pc2=n0,y=0,z=0

pc1=m0,x=2,pc2=n1,y=1,z=2

Page 34: Modeling Software Systems Lecture 2 Book: Chapter 4.

Bank with one teller

$1M

$3M $0M

$1M

deposit robbery

deposit

$1.1M

$3.1M

depositdeposit

Page 35: Modeling Software Systems Lecture 2 Book: Chapter 4.

Partial order execution 1

$1M

$3M $0M

$1M

deposit robbery

$3.1M

deposit

Page 36: Modeling Software Systems Lecture 2 Book: Chapter 4.

Partial order execution 2

$1M

$0M

$1M

robbery

deposit

$1.1M

$3.1M

deposit

Page 37: Modeling Software Systems Lecture 2 Book: Chapter 4.

L0:While True do NC0:wait(Turn=0); CR0:Turn=1endwhile ||L1:While True do NC1:wait(Turn=1); CR1:Turn=0endwhile

T0:PC0=L0PC0:=NC0T1:PC0=NC0/\Turn=0PC0:=CR0T1’:PC0=NC0/\Turn=1PC0:=NC0T2:PC0=CR0(PC0,Turn):=(L0,1)

T3:PC1==L1PC1=NC1T4:PC1=NC1/\Turn=1PC1:=CR1T4’:PC1=NC1/\Turn=0PC1:=N1T5:PC1=CR1(PC1,Turn):=(L1,0)

Initially: PC0=L0/\PC1=L1

Bust waiting

Page 38: Modeling Software Systems Lecture 2 Book: Chapter 4.

[](Turn=0--><>Turn=1)

Turn=0L0,L1

Turn=0L0,NC1

Turn=0NC0,L1

Turn=0CR0,NC1

Turn=0NC0,NC1

Turn=0CR0,L1

Turn=1L0,CR1

Turn=1NC0,CR1

Turn=1L0,NC1

Turn=1NC0,NC1

Turn=1NC0,L1

Turn=1L0,L1

Page 39: Modeling Software Systems Lecture 2 Book: Chapter 4.

Fairness

Restriction on the set of ‘legal’ sequences. Weak process fairness: if some process is

enabled continuously from some state, it will be executed.

Weak transition fairness: if some transition is enabled continuously from some state, it will be executed.

Strong process fairness: if some process is enabled infinitely often, it will be executed (infinitely often).

Strong transition fairness: if some transition is enabled infinitely often, then it will be executed.

Page 40: Modeling Software Systems Lecture 2 Book: Chapter 4.

Example

P1::x:=1 P2::while y=0 do [z:=z+1 [] if x=1 then

y:=1] end while

Initially: x=0 /\ y=0 /\ z=0 /\pc1=l0 /\ pc2=r0

Termination? Termination of P1?

No fairness?. Nothing guaranteed

Weak transition (process) fairness? P1 terminates

Strong process fairness? P1 terminates.

Strong transition fairness? P1 and P2 terminate.

Page 41: Modeling Software Systems Lecture 2 Book: Chapter 4.

Hierarchy of fairness assumptions

Strong transition

weak process

weak transition

Strong process

φ ψ

If φ holds then also ψ.

If a sequence is fair w.r.t. φ it is also fair w.r.t. Ψ.

A system which assumes φhas no more executions than one assuming Ψ