Communication and Concurrency CCS R Milner A Calculus

  • Slides: 56
Download presentation
Communication and Concurrency: CCS R. Milner, “A Calculus of Communicating Systems”, 1980

Communication and Concurrency: CCS R. Milner, “A Calculus of Communicating Systems”, 1980

Why calculi? • Prove properties on programs and languages • Principle: tiny syntax, small

Why calculi? • Prove properties on programs and languages • Principle: tiny syntax, small semantics, to be handled on paper or mechanically • Prove properties on the principles of a language or a programming paradigm • Examples: lambda calculus, sigma calculus, …

Static semantics : examples • Checks non-syntactic constraints • compiler front-end : - declaration

Static semantics : examples • Checks non-syntactic constraints • compiler front-end : - declaration and utilisation of variables, - typing, scoping, … static typing => no execution errors ? ? ? • or back-ends : - optimisers • defines legal programs : - Java byte-code verifier - Java. Card: legal acces to shared variables through firewall What can we do/know about a program without executing it? Mastère RSD - TC 4 oct-nov 2007 3

Dynamic semantics • Gives a meaning to the program (a semantic value) • Describes

Dynamic semantics • Gives a meaning to the program (a semantic value) • Describes the behaviour of a (legal) program • Defines a language interpreter |- e -> e ’ let i=3 in 2*i -> 6 Objective = to prove properties on Program execution (determinacy, subject reduction, …) Mastère RSD - TC 4 oct-nov 2007 4

The different semantic families • Denotational semantics - mathematical model, high level, abstract •

The different semantic families • Denotational semantics - mathematical model, high level, abstract • Axiomatic semantics - provides the language with a theory for proving properties / assertions of programs • Operational semantics - computation of the successive states of an abstract machine - used to build evaluators, simulators. Mastère RSD - TC 4 oct-nov 2007 5

What about concurrency and communication? • Different timing (synchronous/asynchronous …) • Different programming models

What about concurrency and communication? • Different timing (synchronous/asynchronous …) • Different programming models (what is the unit of concurrency? What is sufficient to characterize an execution? . . . ? ) • Interaction between communication/concurrency/shared memory! Through CCS, this course is a simple study of synchronous communications

SEMANTICS

SEMANTICS

Operational Semantics • Describes the computation • States and configuration of an abstract machine:

Operational Semantics • Describes the computation • States and configuration of an abstract machine: - Stack, memory state, registers, heap. . . • Abstract machine transformation steps • Transitions: current state -> next state • Several different operational semantics 9

Natural Semantics : big steps (Kahn 1986) • Defines the results of evaluation. •

Natural Semantics : big steps (Kahn 1986) • Defines the results of evaluation. • Direct relation from programs to results env |- prog => result - env: binds variables to values - result: value given by the execution of prog Reduction Semantics : small steps describes each elementary step of the evaluation • rewriting relation : reduction of program terms • stepwise reduction: <prog, s> -> <prog’, s ’> – infinitely, or until reaching a normal form. 10

Labelled Transition Systems (LTS) • Basic model for representing reactive, concurrent, parallel, communicating systems.

Labelled Transition Systems (LTS) • Basic model for representing reactive, concurrent, parallel, communicating systems. • Definition: l l l < S, s 0, L, T> S = set of states S 0 S = initial state L = set of labels (events, communication actions, etc) T S x L x S = set of transitions a l Notation: s 1 s 2 = (s 1, a, s 2) T Mastère RSD - TC 4 oct-nov 2007 11

An example

An example

Deduction Rules

Deduction Rules

CCS – SYNTAX AND SEMANTICS

CCS – SYNTAX AND SEMANTICS

CCS syntax • • • Channel names: a, b, c , . . .

CCS syntax • • • Channel names: a, b, c , . . . Co-names: Silent action: τ Actions: Processes:

A tiny example Labelled graph • vertices: process expressions • labelled edges: transitions •

A tiny example Labelled graph • vertices: process expressions • labelled edges: transitions • Each derivable transition of a vertex is depicted • Abstract from the derivations of transitions

CCS : behavioural semantics (1) Operators and rules • Action prefix: • Communication: •

CCS : behavioural semantics (1) Operators and rules • Action prefix: • Communication: • Parallelism

CCS : behavioural semantics (2) Operators and rules • Non-deterministic choice • Scope restriction

CCS : behavioural semantics (2) Operators and rules • Non-deterministic choice • Scope restriction • Recursive definition

Derivations (construction of each transition step) a. P | Q Prefix a Par-L a.

Derivations (construction of each transition step) a. P | Q Prefix a Par-L a. R a P|Q (a. P | Q) | a. R (P Prefix R Par-2 | Q) | R Par-2(Par_L(Prefix), Prefix) Another one : Par-L(Par_L(Prefix)) (a. P | Q) | a. R One amongst 3 possible derivations a (P | Q) | a. R 19

EQUIVALENCES 20

EQUIVALENCES 20

Behavioural Equivalences • Intuition: - Same possible sequences of observable actions - Finite /

Behavioural Equivalences • Intuition: - Same possible sequences of observable actions - Finite / infinite sequences - Various refinements of the concept of observation • Definition: Trace Equivalence For a LTS (S, s 0, L, T) its Trace language T is the set of finite sequences {(t = t 1, …, tn such that s 0, …, sn Sn+1, and (sn-1, tn, sn) T} Two LTSs are Trace equivalent iff their Trace languages are equal. Corresponding Ordering: Trace inclusion 21

Trace Languages, Examples • Those 2 systems are trace equivalent: a b c ≡

Trace Languages, Examples • Those 2 systems are trace equivalent: a b c ≡ a b a c T = {(), (a, b), (a, c)} • A trace language can be an infinite set: a b T = {(), (a, a), (a, …, a), … (a, b), (a, a, …, a, b), …} 22

Bisimulation • Behavioural Equivalence non distinguishable states by observation: two states are equivalent if

Bisimulation • Behavioural Equivalence non distinguishable states by observation: two states are equivalent if for all possible transitions labelled by the same action, there exist equivalent resulting states. - • Bisimulations ~ R Sx. S is a simulation iff - It is a equivalence relation act - (p, q) R, (p, l, p’) T => q’/ (q, l, q’) T and (p’, q’) R - R is a bisimulation if the same condition hold with q too: (p, q) R, (q, l, q’) T => q’/ (q, l, q’) T and (p’, q’) R act ~ • ~ is the coarsest bisimulation 2 LTS are bisimilar iff their initial states are in ~ quotients = canonical normal forms 23

Transitivity • If R, S are bisimulations, then so is their composition RS =

Transitivity • If R, S are bisimulations, then so is their composition RS = {(P, P’) | ∃ Q. P R Q and Q S P’} • In particular, ∼∼ ⊆ ∼, i. e. , bisimilarity is transitive.

Bisimulation • More precise than trace equivalence : B 0 A 1 a c

Bisimulation • More precise than trace equivalence : B 0 A 1 a c b A 2 A 3 ~b a a B 1 B 3 B 2 c No state in B is equivalent to A 1 B 4 • Preserves deadlock properties. • Can be built by adding elements in the equivalence relation • Coinductive definition (biggest set verifying …) 25

Bisimulation • Congruence laws: P 1~P 2 => a. P 1 ~ a: .

Bisimulation • Congruence laws: P 1~P 2 => a. P 1 ~ a: . 2 ( P 1, P 2, a) P 1~P 2, Q 1~Q 2 => P 1+Q 1 ~ P 2+Q 2 P 1~P 2, Q 1~Q 2 => P 1|Q 1 ~ P 2|Q 2 Etc… • ~ is a congruence for all CCS operators : for any CCS context C[. ], C[P] ~ C[Q] <=> P~Q Basis for compositional proof methods • Maximal trace is not an equivalence 26

Observational Equivalences • Weak bisimulation Abstraction: hidden actions μ - allows for arbitrary many

Observational Equivalences • Weak bisimulation Abstraction: hidden actions μ - allows for arbitrary many internal actions ⇒ act - * * act * 27

Weak bisimulation • The following def is a tractable version of weak bisimulation: A

Weak bisimulation • The following def is a tractable version of weak bisimulation: A weak bisimulation is a relation R such that μ μ P R Q ⇒ ∀μ, P, P’ (P →P’ ⇒ ∃Q’. Q ⇒Q’ and P’ R Q’) and conversely • Note the dissymetry between the use of →on the left and of ⇒ on the right • Two processes are weakly bisimilar if (notation P ≈ Q) if there exists a weak bisimulation R such that P R Q.

Branching bisimulation • only staying in equivalent states Still existence of a canonical minimal

Branching bisimulation • only staying in equivalent states Still existence of a canonical minimal automata Computation is polynomial a a

ADDITIONAL NOTATIONS AND CONSTRUCTS

ADDITIONAL NOTATIONS AND CONSTRUCTS

Alternative Notations • a little more complex for several definitions -> exercise? • Input/output:

Alternative Notations • a little more complex for several definitions -> exercise? • Input/output: a=? a ; a = !a • | or || 31

Extension: Parameterized actions • input of data at port a, a(x ). E •

Extension: Parameterized actions • input of data at port a, a(x ). E • a(x ) binds free occurrences of x in E. • Port a represents {a(v ) : v ∈ D } where D is a family of data values • Output of data at port a, a(e ). E where e is a data expression. • Transition Rules: depend on extra machinery for expression evaluation. Let Val(e ) be data value in D (if there is one) to which e evaluates a(v ) • R (in) a(x ). E → E {v /x } if v ∈ D where {v /x } is substitution a (v ) • R (out) a(e ). E → E if Val(e ) = v 32

Example: a register Regi = read(i ). Regi + write(x ). Reg x

Example: a register Regi = read(i ). Regi + write(x ). Reg x

EXAMPLES

EXAMPLES

philosopher Drop_right! Example: dining philosophers chopstick Drop_left! Drop? Take_left Take_right Take_left Eat Take? Idle

philosopher Drop_right! Example: dining philosophers chopstick Drop_left! Drop? Take_left Take_right Take_left Eat Take? Idle Drop_left Drop_right (recidling, eating. (idle. idling + take_left. take_right. eating + take_right. take_left. eating, eating + drop_left. drop_right. idling + drop_right. drop_left. idling) Deadlock or not ? Mutual exclusion ?

(trivial) example: Milner’s Scheduler • Processes iteratively start and finish executing tasks (one task

(trivial) example: Milner’s Scheduler • Processes iteratively start and finish executing tasks (one task per process) • Task starts are cyclically ordered cycler = . start. ( . 0 || end. cycler) scheduler_3 = local 1, 2, 3 in ( [ 1/ , 2/ , start 1/start, end 1/end] cycler || [ 2/ , 3/ , start 2/start, end 2/end] cycler || [ 3/ , 1/ , start 3/start, end 3/end] cycler || 1. 0) vérification des propriétés ?

Scheduler_2 expanded tau start 1 end 2 end 1 start 2 tau start 1

Scheduler_2 expanded tau start 1 end 2 end 1 start 2 tau start 1 end 2 end 1 start 2 tau end 1

Scheduler_2 reduced tau start 1 end 2 end 1 start 2 tau start 1

Scheduler_2 reduced tau start 1 end 2 end 1 start 2 tau start 1 end 2 end 1 start 2 tau end 1

Scheduler_2 reduced end 1 start 1 end 2 end 1 start 2 end 1

Scheduler_2 reduced end 1 start 1 end 2 end 1 start 2 end 1

CONCLUSION • A synchronous communication language • A (complex but) efficient notion of equivalence

CONCLUSION • A synchronous communication language • A (complex but) efficient notion of equivalence on processes • What is missing? - Channel communication (like in pi-calculus) -> much more complex - No computational construct by nature

EXERCISES

EXERCISES

Example: Alternated Bit Protocol ? imss !in 0 Fwd_channel ? ack ? ims 1

Example: Alternated Bit Protocol ? imss !in 0 Fwd_channel ? ack ? ims 1 s ? ack 1 !in 1 !oms s ? out 0 !ack 1 ? out 0 ? ack 0 ? ims s ? ack 0 !oms s Bwd_channel emitter !oms s ? out 1 !ack 0 receiver Hypotheses: channels can loose messages Write in CCS ? Requirement: the protocol ensures no loss of messages 42

Example: Alternated Bit Protocol (2) • emitter = let rec {em 0 = ?

Example: Alternated Bit Protocol (2) • emitter = let rec {em 0 = ? ack 1 : em 0 + ? imss: em 1 and em 1 = !in 0 : em 1 + ? ack 0 : em 2 and em 2 = ? ack 0 : em 2 + ? imss : em 3 and em 3 = !in 1 : em 3 + ? ack 1 : em 0 } in em 0 • ABP = local {in 0, in 1, out 0, out 1, ack 0, ack 1, …} in emitter || Fwd_channel || Bwd_channel || receiver Mastère RSD - TC 4 oct-nov 2007 43

Example: Alternated Bit Protocol (3) Channels that loose and duplicate messages (in 0 and

Example: Alternated Bit Protocol (3) Channels that loose and duplicate messages (in 0 and in 1) but preserve their order ? • Exercise : 1) Draw an LTS describing the loosy channel behaviour 2) Write the same description in CCS Mastère RSD - TC 4 oct-nov 2007 44

Exercise 2

Exercise 2

Exercice 3 : Bisimulations Are those 3 LTSs equivalent by: ? in 0 -

Exercice 3 : Bisimulations Are those 3 LTSs equivalent by: ? in 0 - Strong bisimulation? !out 0 In each case, give a proof. ? in 0 !out 0 ? in 1 ? in 0 - Weak bisimulation ? !out 0

Exercice 3 : Bisimulation ? in 0 !out 0 • A 1 !out 0

Exercice 3 : Bisimulation ? in 0 !out 0 • A 1 !out 0 Exercice : 1) Compute the strong minimal automaton for A 1. 2) Compute the weak minimal automaton for A 1.

Exercise 5 def • Compare the construct = and rec. K : 1. Let

Exercise 5 def • Compare the construct = and rec. K : 1. Let us start by a simple pair of processes 2. 3. Suppose rec can accept several variables: rec (K=P, L=Q) express the same term Is it possible to express the same thing with a single variable K? Here are some possible hints: l l l Define a recursive process All that contains A and B and can trigger each of them by the reception of a message on channel c. A or c. B (we suppose c. A and c. B cannot be used elsewhere) What kind of equivalence between the two expressions do you have?

CORRECTION

CORRECTION

Exercice: Alternated Bit Protocol Correction (1): Channels that loose and duplicate messages (in 0

Exercice: Alternated Bit Protocol Correction (1): Channels that loose and duplicate messages (in 0 and in 1) but preserve their order ? 1) Draw an automaton describing the loosy channel behaviour !out 1 ? in 0 !out 1 !out 0 • It is a symmetric system, receiving ? in 0 and ? in 1 messages, then delivering 0 , 1 or more times the corresponding !out 0 or !out 1 message. • On each side (bit 0 or 1), the initial state has a single transition for the reception. • In the next state, it can either : return silently to the initial state (= lose the message), deliver the message and return to the initial state (exactly one delivery), or deliver the message and stay in the same state (thus enabling duplication).

Exercice: Alternated Bit Protocol Correction (2): Channels that loose and duplicate messages (in 0

Exercice: Alternated Bit Protocol Correction (2): Channels that loose and duplicate messages (in 0 and in 1) but preserve their order ? 2) Write it in CCS !out 1 ? in 0 !out 1 !out 0 • Lousy channel = let rec {ch 0 = ? in 0 : ch 1 + ? in 1: ch 2 and ch 1 = : ch 1 + : ch 0 + !out 0 : ch 1 + !out 0 : ch 0 and ch 2 = : ch 2 + : ch 0 + !out 0 : ch 2 + !out 0 : ch 0 } in ch 0 !out 0

Exercice: Alternated Bit Protocol Correction (3): Channels that loose and duplicate messages (in 0

Exercice: Alternated Bit Protocol Correction (3): Channels that loose and duplicate messages (in 0 and in 1) but preserve their order ? ? in 0 !out 0 ? in 0 Other Solutions: !out 0 More generally, parameterized model : ? in(x) x !out(x)

Exercice 2 : Bisimulations Are those 3 LTSs equivalent by: ? in 0 1.

Exercice 2 : Bisimulations Are those 3 LTSs equivalent by: ? in 0 1. 0 1. 1 - Strong bisimulation? !out 0 States 1. 0 and 1. 1 are different because 1. 0 can do ? in 0 and 1. 1 cannot. ? in 0 2. 1 2. 0 NO ! Need find non equivalent states. E. g. counter example for 1 ≠ 2: !out 0 Then 1. 1 and 2. 1 are different because 1. 1 can do !out 0 -> 1. 0, while no 2. 1 !out 0 transitions can go to a state equivalent to 1. 0. - Weak bisimulation ? YES. Exhibit a partition of equivalent states: ? in 1 ? in 0 !out 0 1={1. 0, 2. 0}, 2={1. 1, 2. 1} Check all possible ( *a *) transitions: 1 - !in 0 -> 2, … , 2 - !out 0. * -> 1 Remark: this transition set defines the minimal representant modulo weak bisimulation…

Exercice 4 : Produit synchronisé Compute the synchronized product of the LTS representing the

Exercice 4 : Produit synchronisé Compute the synchronized product of the LTS representing the ABP emitter with the (forward) Channel: ? imss local {in 0, in 1} in (Emitter || Channel) !in 0 ? ack 1 ? imss 0 1 ? ack 0 ? ack 1 3 2 2 ? imss !in 1 ? ack 0 ? in 1 !out 1 ? in 0 !out 1 0 !out 0 1 !out 0

Exercice 4 : Produit synchronisé Correction ? partially… local {in 0, in 1} in

Exercice 4 : Produit synchronisé Correction ? partially… local {in 0, in 1} in (Emitter || Channel) !out 0 ? ack 1 ? imss 0, 0 1, 0 ? ack 1 !out 1 !in 1 3, 0 2, 0 ? imss !out 0 1, 1 ? ack 0 2, 1 !out 0 ? ack 0 3, 1 ? imss !out 0

Exercice 4 : Produit synchronisé Correction ? Tool generated LTS…

Exercice 4 : Produit synchronisé Correction ? Tool generated LTS…