topic 1 introduction topic 2 modelling processes with fsp
play

Topic 1: Introduction Topic 2: Modelling Processes with FSP Alan - PowerPoint PPT Presentation

COMP30112: Concurrency Topic 1: Introduction Topic 2: Modelling Processes with FSP Alan Williams Room 2.107: email: alanw@cs.man.ac.uk February 2007 Outline Topic 1: Introduction General Background On Concurrency Examples Implementation


  1. COMP30112: Concurrency Topic 1: Introduction Topic 2: Modelling Processes with FSP Alan Williams Room 2.107: email: alanw@cs.man.ac.uk February 2007

  2. Outline Topic 1: Introduction General Background On Concurrency Examples Implementation Topic 2: Modelling Processes with FSP Labelled Transition Systems FSP: Basic Elements Summary

  3. General Comments • Some concepts familiar from CS205, CS2081, CS231 • We follow much of Magee and Kramer, but more on modelling • Java ?? CS2051 • Java used to illustrate — but NOT a programming course

  4. Supporting and Background Material Books Jeff Magee and Jeff Kramer. Concurrency: State Models and Java Programs. Wiley, 1999. R. Milner. Communication and Concurrency. Prentice-Hall, 1989. C.A.R. Hoare. Communicating Sequential Processes. Prentice-Hall, 1985. Java and LTSA Demos: on teaching domain. See http://www.cs.man.ac.uk/csonly/courses/COMP30112/index.html Exercises: offline and in lectures Lecture Slides: hardcopy and PDF Notes on FSP

  5. Assessment 2 hour examination

  6. What is Concurrency? A set of sequential programs executed in abstract parallelism • thread [of control] • shared memory • multi-threading • protected work-space • light-weight threads • parallel processing • message-passing • multi-processing (synchronous or • multi-tasking asynchronous)

  7. Why Concurrency • often more closely fits intuition • performance issues • increased responsiveness and throughput (esp. GUIs)

  8. Why is concurrency hard? • algorithm development • efficiency and performance • simulation and testing: NON DETERMINISM • analysis of properties: deadlock, livelock, fairness, liveness, etc. We will consider: Modelling, Analysis and Implementation (in Java)

  9. Modelling Concurrency • a ‘simplified’ representation of the real world? • modelling before implementing • model captures interesting aspects: concurrency • animation • analysis • Model Description Language: FSP ( Finite State Processes ) • Models: LTS ( Labelled Transition Systems )

  10. Example: Cruise Control System • Does it do what we expect? Is it safe?

  11. FSP: Animation INPUTSPEED = ( engineOn -> CHECKSPEED ), CHECKSPEED = ( speed -> CHECKSPEED | engineOff -> INPUTSPEED ).

  12. Structure Diagrams CONTROL CRUISE SENSOR CONTROLLER SCAN Sensors Engine Prompts INPUT SPEED speed setThrottle THROTTLE SPEED CONTROL set Sensors = {engineOn,engineOff,on,off, resme, brake, accelerator} set Engine = {engineOn,engineOff} set Prompts = {clearSpeed,recordSpeed, enableControl,disableControl}

  13. Implementation in Java • Thread class; Runnable interface • starting, stopping, suspending threads • mutual exclusion: synchronized methods and code blocks • monitors, condition synchronization • wait , notify , notifyAll • sleep , interrupt • suspend , resume , stop • properties: safety, liveness

  14. First Exercise DAY : A Day In the Life Of: • DAY1: Get up — action: getUp , • then have a cup of tea — action: tea • then work — action: work You Do It: LTS for DAY1 • DAY2: Now repeat the Day — action: goHome You Do It: LTS for DAY2 • DAY3: Now be able to choose coffee — action: coffee — instead of tea You Do It: LTS for DAY3

  15. Labelled Transition Systems What is an LTS?: LTS = ( S , A , σ, s 0 ) S : set of states S A : A ⊆ Act alphabet where σ : transition relation σ ⊆ ( S × A × S ) s 0 initial state s 0 ∈ S Act is our set of atomic transition labels, or actions.

  16. FSP: A Textual Representation for LTS FSP - Finite State Processes What FSP Constructs Are Required?? • DAY1 : sequence • DAY1 : STOP • DAY2 : process definition, with recursion • DAY3 : choice

  17. Action Prefix If x is an action and P is a process then ( x -> P ) describes a process that initially engages in the action x and then behaves exactly as described by P . ( once -> STOP ) . Convention: • actions begin with a lower case letter • PROCESS NAMES begin with an upper case letter • STOP is a specially pre-defined FSP process name. You Do It: FSP for DAY1

  18. Process Definition Basic form: ProcId = process expression • The meaning of ProcId will be given by the meaning of process expression . • ProcId should start with an upper-case letter. • Recursion: ProcId can occur in process expression . (more complex forms possible — see later. . . ) You Do It: FSP for DAY2

  19. Choice • If x and y are actions then ( x -> P | y -> Q ) describes a process which initially engages in either of the actions x or y . • After that the subsequent behaviour is described by – P if the first action was x , – Q if the first action was y . You Do It: FSP for DAY3

  20. Example: Various Switches Repetitive behaviour uses recursion: SWITCH = OFF , = ( on -> ON ) , OFF ON = ( off -> OFF ) . Substituting to get a more concise definition: SWITCH = OFF , = ( on -> off -> OFF ) . OFF And again: SWITCH = ( on -> off -> SWITCH ) . You Do It: Are these FSP SWITCH defintions the same??

  21. Example: Traffic Light FSP model of a traffic light: = ( red -> amber -> green TRAFFICLIGHT -> amber -> TRAFFICLIGHT ) . You Do It: What is LTS generated? Use LTSA You Do It: Trace red -> amber -> green -> amber -> red -> amber -> green -> · · ·

  22. Example: Vending Machine FSP model of a drinks machine: DRINKS = ( red -> coffee -> DRINKS | blue -> tea -> DRINKS ) . You Do It: LTS generated using LTSA You Do It: Possible traces

  23. Non-Deterministic Choice Process ( x -> P | x -> Q ) describes a process which engages in x and then behaves as either P or Q . = ( toss -> HEADS | toss -> TAILS ) , COIN HEADS = ( heads -> COIN ) , = ( tails -> COIN ) . TAILS Tossing a coin You Do It: Possible traces

  24. Syntactic Sugar: Indexed Processes and Actions Single slot buffer that inputs a value in the range 0 to 3 and then outputs a value: BUFF = ( in [ i : 0 .. 3 ] -> out [ i ] -> BUFF ) . equivalent to BUFF = ( in [ 0 ] -> out [ 0 ] -> BUFF | in [ 1 ] -> out [ 1 ] -> BUFF | in [ 2 ] -> out [ 2 ] -> BUFF | in [ 3 ] -> out [ 3 ] -> BUFF ) .

  25. or using a constant and indexed process BUFF [ i ] : = 3 const N BUFF = ( in [ i : 0 .. N ] -> BUFF [ i ]) , BUFF [ i : 0 .. N ] = out [ i ] -> BUFF ) . or using a process parameter with default value: BUFF ( N = 3 ) = ( in [ i : 0 .. N ] -> out [ i ] -> BUFF ) .

  26. Guarded Actions The choice ( when B x -> P | y -> Q ) describes a process that is like ( x -> P | y -> Q ) except that the action x can only be chosen when the guard B is true.

  27. Example: A Counter COUNT ( N = 3 ) = COUNT [ 0 ] , COUNT [ i : 0 .. N ] = ( when ( i < N ) inc -> COUNT [ i + 1 ] | when ( i > 0 ) dec -> COUNT [ i − 1 ] ) .

  28. Example: A Countdown Timer A countdown timer which beeps after N ticks, or can be stopped. COUNTDOWN ( N = 3 ) = ( start -> COUNTDOWN [ N ]) , COUNTDOWN [ i : 0 .. N ] = ( when ( i > 0 ) tick -> COUNTDOWN [ i − 1 ] | when ( i == 0 ) beep -> STOP | stop -> STOP ) . You Do It: LTS

  29. Example: What is this? You Do It: What is the following FSP process equivalent to const False = 0 P = (when (False) doanything -> P).

  30. Constant and Range Declarations index expressions to model a calculation: const N = 1 range T = 0..N range R = 0..2*N SUM = (in[a:T][b:T] -> TOTAL[a+b]), TOTAL[s:R] = (out[s] -> SUM). You Do It: Write SUM using basic FSP

  31. Process Alphabets • The alphabet of a process is the set of actions in which it is allowed to engage. • This is usually determined implicitly as the actions in which it can engage. • But the implicit alphabet can be extended: = ( write [ 1 ] -> write [ 3 ] -> WRITER ) WRITER + { write [ 0 .. 3 ] } . The alphabet of WRITER is the set { write [ 0 .. 3 ] } ; i.e. the set { write [ 0 ] , write [ 1 ] , write [ 2 ] , write [ 3 ] } .

  32. FSP: Summary Forms of process expression Examples prefix action ( coffee -> DRINKS ) guarded action ( when ( i == 0 ) beep -> STOP ) deterministic choice ( red -> COFFEE | blue -> TEA ) non-deterministic choice ( toss -> HEADS | toss -> TAILS ) ( out [ i ] -> BUFF ) dependent process indexed choice ( in [ i : 0 .. 3 ] -> BUFF [ i ]) � DRINKS , process name BUFF [ i ]

  33. Process equation: process name = process expression  declarations   main process equation ,     local process equation ,      . Process definition: .    .     local process equation ,     local process equation .

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend