Introduction to CSP Alexandre Mota acmcin ufpe br
Introduction to CSP Alexandre Mota (acm@cin. ufpe. br)
Agenda n Fundamental concepts n n n Process Communication Alphabet Basic behaviour State Alternating behaviour
Fundamental Concepts
Process n n n Basic unit to capture behaviour In general, we use a set of processes to get modularity It is defined by equation(s) n P = (behaviour) n n Similar to functional programming [although it is not a function!!!] Process names denote interesting system states/modules
Process … Processes
Communication n n Term ‘communication’ comes from the notion of interaction/observation/synchronisation It occurs between at least two parts [Which are? ] A sequence of communications tells us a history (possible behaviour of a system trace) A communication can be: n Event (no data communication synchronisation) n Channel (a typed value is communicated) data
Alphabet n n Each process has its own alphabet [Hoare 85] – ( P) The whole specification determines the alphabet [Roscoe 98] – ( ) n n Alphabet is the union of all communications present in the body of all processes Determines the abstraction level
Abstraction Level n It depends on what one is interested in observing n n n some. Digit vs digit_0, digit_1, …, digit_9 Thus, a communication can represent a set of more basic observations It dictates the success of a tool-based analysis n The problem of state explosion
STOP n n It is a terminal process The most basic non-communicating and non-progressing process n n In general, it is only used to denote broken functionality n n Interaction is forbidden Exercises (broken car and light) When it surprisingly appears we have a deadlock situation
STOP
SKIP n n Similarly to STOP, SKIP is a terminal process However, its occurrence means a successful termination n Exercises (Turning off car and light) It only communicates a special event ( ) After that, no communication and progress is possible n Curiosity about FDR (STOP vs SKIP)
SKIP
Useful Behaviour n The most basic construct to model behaviour is the prefix operator (->) n n n The process a -> P waits indefinitely by a, and then behaves like P Example: n n Communication -> Process Two. Steps = left. Foot -> right. Foot -> SKIP (Exercises) Turning off the light and light is broken…
Prefix (a -> P) a P
A Complete Specification n It is a combination of n Alphabet declarations n n Function and set definitions n n n Odd(n) = (n % 2 == 1) T = {0, 1, 2} And process definitions n n channel up, down P = up -> down -> STOP And, in general, following this ordering
Continuous Behaviour n n n Various systems have a series of repetitive behaviour And these repetitions can be infinite Infinite behaviour becomes recursion n n P = (sequence of communications) -> P Right-side process name is replaced by a left-side process definition n The processes can be different
Channels n n Communications that carry data Declaration needs an associated type n n channel a: T And the correct use needs one of the three operators: ? (input), ! (output) and. (simple separator) n Example: a? var, a!exp, a. exp
Events vs Channels n n n They are conceptually distinct But, in practice, a channel is indeed a set of events Thus, the channel a: {0, 1} is the set of events {a. 0, a. 1} n n Note the use of the. operator as a separator Channels simply have a more elegant and readable presentation than events
State n n n When deadling with dynamic data structures It is captured by process parameters Parameters are not typed (Dynamic type checking occurs) n n Assignment is represented by recursive calls n n This can yield polymorphic solutions P(n) = add. One -> P(n + 1) Parametrised processes must be instantiated n We need P(0), or P(10) to exploit P(n)
Conditional Behaviour n Data can be used to exhibit different behaviours n n P(y) = a? x -> if x == y then equal -> P else diff -> P The process b & P (guard) is a shorthand of if b then P else STOP
Conditional (if b then P else Q) b b P Q
Alternative Behaviour n If the environment can interfere then we use n n P [ ] Q (Deterministic or external choice) Otherwise n P |~| Q (Non-deterministic or internal choice)
External Choice P a P = a -> Q [ ] b -> R a b OR b
External Choice (P [ ] Q) a b P Q Provided that a is a starting event of P and b a starting event of Q
Input and External Choice Let c be a channel of type {e 0, …, e. N} c? x -> P c. e 0 -> P[e 0 / x] [] … [] c. e. N -> P[e. N / x]
Exercise n Present a CSP process which captures the first screen of an ATM machine
Internal Choice P P = a -> Q |~| b -> R a b
Internal Choice (P |~| Q) P Q
Exercise n Present a CSP process which captures the first screen of an ATM machine n After selecting one of the possible services, the process can succeed/fail to satisfy it
Tool Support n Pro. BE n n FDR n n CSP animator (Useful for self-learning) CSP model-checker (Useful for property/refinement analysis) Casper n CSP protocol design (Abstract protocol design)
References n n Roscoe, A. W. Theory and Practice of Concurrency. Prentice-Hall, 1998. Hoare, C. A. R. Communicating Sequential Processes. Prentice-Hall, 1985.
- Slides: 31