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

topic 1 introduction topic 2 modelling processes with fsp
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 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

slide-2
SLIDE 2

Outline

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

slide-3
SLIDE 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
slide-4
SLIDE 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

slide-5
SLIDE 5

Assessment

2 hour examination

slide-6
SLIDE 6

What is Concurrency?

A set of sequential programs executed in abstract parallelism

  • thread [of control]
  • multi-threading
  • light-weight threads
  • parallel processing
  • multi-processing
  • multi-tasking
  • shared memory
  • protected work-space
  • message-passing

(synchronous or asynchronous)

slide-7
SLIDE 7

Why Concurrency

  • often more closely fits intuition
  • performance issues
  • increased responsiveness and throughput (esp. GUIs)
slide-8
SLIDE 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)

slide-9
SLIDE 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)
slide-10
SLIDE 10

Example: Cruise Control System

  • Does it do what we expect? Is it safe?
slide-11
SLIDE 11

FSP: Animation

INPUTSPEED = ( engineOn -> CHECKSPEED ), CHECKSPEED = ( speed -> CHECKSPEED | engineOff -> INPUTSPEED ).

slide-12
SLIDE 12

Structure Diagrams

SENSOR SCAN CRUISE CONTROLLER SPEED CONTROL INPUT SPEED THROTTLE CONTROL

speed Sensors setThrottle Engine Prompts

set Sensors = {engineOn,engineOff,on,off, resme, brake, accelerator} set Engine = {engineOn,engineOff} set Prompts = {clearSpeed,recordSpeed, enableControl,disableControl}

slide-13
SLIDE 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
slide-14
SLIDE 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

slide-15
SLIDE 15

Labelled Transition Systems

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

slide-16
SLIDE 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
slide-17
SLIDE 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

slide-18
SLIDE 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

slide-19
SLIDE 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

slide-20
SLIDE 20

Example: Various Switches

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

slide-21
SLIDE 21

Example: Traffic Light

FSP model of a traffic light: TRAFFICLIGHT = (red->amber->green

  • >amber->TRAFFICLIGHT).

You Do It: What is LTS generated? Use LTSA You Do It: Trace red->amber->green->amber->red ->amber->green-> · · ·

slide-22
SLIDE 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

slide-23
SLIDE 23

Non-Deterministic Choice

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

slide-24
SLIDE 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 ).

slide-25
SLIDE 25
  • r using a constant and indexed process BUFF[i]:

const N = 3 BUFF = (in[i : 0..N]->BUFF[i]), BUFF[i : 0..N] = out[i]->BUFF).

  • r using a process parameter with default value:

BUFF(N = 3) = (in[i : 0..N]->out[i]->BUFF).

slide-26
SLIDE 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.

slide-27
SLIDE 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] ).

slide-28
SLIDE 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

slide-29
SLIDE 29

Example: What is this?

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

slide-30
SLIDE 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

slide-31
SLIDE 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:

WRITER = (write[1]->write[3]->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]}.

slide-32
SLIDE 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) dependent process (out[i]->BUFF) indexed choice (in[i : 0..3]->BUFF[i]) process name DRINKS, BUFF[i]

slide-33
SLIDE 33

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