78
Topic 1: Introduction Topic 2: Modelling Processes with FSP - I COMP30112: Concurrency Introduction to Course & Introduction to FSP Howard Barringer Room KB2.20: email: [email protected] January 2008

COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

COMP30112: ConcurrencyIntroduction to Course & Introduction to FSP

Howard Barringer

Room KB2.20: email: [email protected]

January 2008

Page 2: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Acknowledgement

This course was initially prepared byDr Alan Williams

and then subsequently updated by myself during sessions 2004/05and 2005/2006.

The material is firmly based on that of:Profs Magee and Kramer

of Imperial College, Dept of Computing, London.

Many thanks to all concerned.

Page 3: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Acknowledgement

This course was initially prepared byDr Alan Williams

and then subsequently updated by myself during sessions 2004/05and 2005/2006.

The material is firmly based on that of:Profs Magee and Kramer

of Imperial College, Dept of Computing, London.

Many thanks to all concerned.

Page 4: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Acknowledgement

This course was initially prepared byDr Alan Williams

and then subsequently updated by myself during sessions 2004/05and 2005/2006.

The material is firmly based on that of:Profs Magee and Kramer

of Imperial College, Dept of Computing, London.

Many thanks to all concerned.

Page 5: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Contents

Topic 1: IntroductionGeneral BackgroundOn ConcurrencyExamplesImplementation

Topic 2: Modelling Processes with FSP - ILabelled Transition SystemsFSP: Basic ElementsSummary

Page 6: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Outline

Topic 1: IntroductionGeneral BackgroundOn ConcurrencyExamplesImplementation

Topic 2: Modelling Processes with FSP - ILabelled Transition SystemsFSP: Basic ElementsSummary

Page 7: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Course Structure and Topics

Lectures Topic

1 Introduction and Overview

5 FSP: Modelling Processes

5 Properties: Safety, liveness

2 Process Equality

2 Java Threads

6 Concurrency Patterns:Mutual Exclusion

Monitors+Semaphores

Producers/Consumers

Readers/Writers

GUIs

Termination

1 Revision

Page 8: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

General Comments

• Some concepts familiar from COMP20051 and COMP20081

• We follow much of Magee and Kramer, but more on modelling

• Java ' COMP20051

• Java used to illustrate — BUT this is NOT a programmingcourse

Page 9: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Supporting and Background Material

Books

Jeff Magee and Jeff Kramer. Concurrency: State Models andJava Programs. 2nd Edition, Wiley, 2006.L. Aceto, A Ingolfsdottir, K. Larsen and J Srba. ReactiveSystems: Modelling, Specification and Verification. CambridgeUniversity Press, 2007.R. Milner. Communication and Concurrency. Prentice-Hall,1989.C.A.R. Hoare. Communicating Sequential Processes.Prentice-Hall, 1985.

LTSA: Magee and Kramer’s modelling and analysis tool(associated with book)

Exercises: offline and in lectures

Lecture Slides: hardcopy and PDF

Notes on FSP

Page 10: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Assessment

2 hour examination

Page 11: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Outline

Topic 1: IntroductionGeneral BackgroundOn ConcurrencyExamplesImplementation

Topic 2: Modelling Processes with FSP - ILabelled Transition SystemsFSP: Basic ElementsSummary

Page 12: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 orasynchronous)

Page 13: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 orasynchronous)

Page 14: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 orasynchronous)

Page 15: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 orasynchronous)

Page 16: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 orasynchronous)

Page 17: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 orasynchronous)

Page 18: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Why use Concurrency?

• often more closely fits intuition

• performance issues

• increased responsiveness and throughput (esp. GUIs)

Page 19: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 (inJava)

Page 20: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 (inJava)

Page 21: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 (inJava)

Page 22: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 (inJava)

Page 23: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 (inJava)

Page 24: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 (inJava)

Page 25: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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)

Page 26: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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)

Page 27: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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)

Page 28: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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)

Page 29: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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)

Page 30: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Outline

Topic 1: IntroductionGeneral BackgroundOn ConcurrencyExamplesImplementation

Topic 2: Modelling Processes with FSP - ILabelled Transition SystemsFSP: Basic ElementsSummary

Page 31: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Example: Cruise Control System

• Does it do what we expect? Is it safe?

Page 32: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

FSP: Animation

INPUTSPEED = ( engineOn -> CHECKSPEED ),CHECKSPEED = ( speed -> CHECKSPEED

| engineOff -> INPUTSPEED ).

Page 33: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Structure Diagrams

SENSORSCAN

CRUISECONTROLLER

SPEED CONTROL

INPUTSPEED THROTTLE

CONTROL

speed

Sensors

setThrottle

EnginePrompts

set Sensors = {engineOn,engineOff,on,off,

resume, brake, accelerator}

set Engine = {engineOn,engineOff}

set Prompts = {clearSpeed,recordSpeed,

enableControl,disableControl}

Page 34: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Outline

Topic 1: IntroductionGeneral BackgroundOn ConcurrencyExamplesImplementation

Topic 2: Modelling Processes with FSP - ILabelled Transition SystemsFSP: Basic ElementsSummary

Page 35: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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

Page 36: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Outline

Topic 1: IntroductionGeneral BackgroundOn ConcurrencyExamplesImplementation

Topic 2: Modelling Processes with FSP - ILabelled Transition SystemsFSP: Basic ElementsSummary

Page 37: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Labelled Transition Systems

What is an LTS?:

LTS = (S ,A, σ, s0)

where

S : set of states SA : alphabet A ⊆ Actσ : transition relation σ ⊆ (S × A× S)s0 initial state s0 ∈ S

Act is our set of atomic transition labels, or actions.

Page 38: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

First Exercise

DAY1: A Day In the Life Of:

• Get up — action: up,

• then have a cup of tea — action: tea

• then work — action: work

F LTS for DAY1? F

• DAY2: Now repeat the Day

F LTS for DAY2? F

• DAY3: Now be able to choose coffee — action: coffee —instead of tea

F LTS for DAY3? F

Page 39: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

First Exercise

DAY1: A Day In the Life Of:

• Get up — action: up,

• then have a cup of tea — action: tea

• then work — action: work

F LTS for DAY1? F

• DAY2: Now repeat the Day

F LTS for DAY2? F

• DAY3: Now be able to choose coffee — action: coffee —instead of tea

F LTS for DAY3? F

Page 40: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

First Exercise

DAY1: A Day In the Life Of:

• Get up — action: up,

• then have a cup of tea — action: tea

• then work — action: work

F LTS for DAY1? F

• DAY2: Now repeat the Day

F LTS for DAY2? F

• DAY3: Now be able to choose coffee — action: coffee —instead of tea

F LTS for DAY3? F

Page 41: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

FSP: A Textual Representation for LTS

FSP - Finite State ProcessesWhat FSP Constructs Are Required??

• sequence

• STOP

• process definition, with recursion

• choice

Page 42: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

FSP: A Textual Representation for LTS

FSP - Finite State ProcessesWhat FSP Constructs Are Required??

• sequence

• STOP

• process definition, with recursion

• choice

Page 43: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

FSP: A Textual Representation for LTS

FSP - Finite State ProcessesWhat FSP Constructs Are Required??

• sequence

• STOP

• process definition, with recursion

• choice

Page 44: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

FSP: A Textual Representation for LTS

FSP - Finite State ProcessesWhat FSP Constructs Are Required??

• sequence

• STOP

• process definition, with recursion

• choice

Page 45: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Outline

Topic 1: IntroductionGeneral BackgroundOn ConcurrencyExamplesImplementation

Topic 2: Modelling Processes with FSP - ILabelled Transition SystemsFSP: Basic ElementsSummary

Page 46: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Action Prefix

If x is an action and P is a process then (x->P) describes aprocess that initially engages in the action x and then behavesexactly 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.

F FSP for DAY1? F

Page 47: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Action Prefix

If x is an action and P is a process then (x->P) describes aprocess that initially engages in the action x and then behavesexactly 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.

F FSP for DAY1? F

Page 48: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Process Definition

Basic form:

ProcId = process expression

The meaning of ProcId will be given by the meaning ofprocess expression.ProcId should start with an upper-case letter.

(more complex forms possible — see later. . . )

F FSP for DAY2? F

Page 49: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Process Definition

Basic form:

ProcId = process expression

The meaning of ProcId will be given by the meaning ofprocess expression.ProcId should start with an upper-case letter.

(more complex forms possible — see later. . . )F FSP for DAY2? F

Page 50: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Choice

• If x and y are actions then (x->P | y->Q) describes a processwhich initially engages in either of the actionsx or y.

• After that the subsequent behaviour is described by• P if the first action was x,• Q if the first action was y.

F FSP for DAY3? F

Page 51: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Choice

• If x and y are actions then (x->P | y->Q) describes a processwhich initially engages in either of the actionsx or y.

• After that the subsequent behaviour is described by• P if the first action was x,• Q if the first action was y.

F FSP for DAY3? F

Page 52: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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).

F Are these FSP SWITCH definitions the same? F

Page 53: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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).

F Are these FSP SWITCH definitions the same? F

Page 54: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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).

F Are these FSP SWITCH definitions the same? F

Page 55: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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).

F Are these FSP SWITCH definitions the same? F

Page 56: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Example: Traffic Light

FSP model of a traffic light:

TRAFFICLIGHT = (red->amber->green->amber->TRAFFICLIGHT).

F LTS generated using LTSA? F

F Trace? F

red->amber->green->amber->red ->amber->green-> · · ·

Page 57: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Example: Traffic Light

FSP model of a traffic light:

TRAFFICLIGHT = (red->amber->green->amber->TRAFFICLIGHT).

F LTS generated using LTSA? F

F Trace? F

red->amber->green->amber->red ->amber->green-> · · ·

Page 58: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Example: Traffic Light

FSP model of a traffic light:

TRAFFICLIGHT = (red->amber->green->amber->TRAFFICLIGHT).

F LTS generated using LTSA? F

F Trace? F

red->amber->green->amber->red ->amber->green-> · · ·

Page 59: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Example: Traffic Light

FSP model of a traffic light:

TRAFFICLIGHT = (red->amber->green->amber->TRAFFICLIGHT).

F LTS generated using LTSA? F

F Trace? F

red->amber->green->amber->red ->amber->green-> · · ·

Page 60: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Example: Vending Machine

FSP model of a drinks machine:

DRINKS = (red->coffee->DRINKS| blue->tea->DRINKS).

F LTS generated using LTSA? F

F Possible traces? F

Page 61: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Example: Vending Machine

FSP model of a drinks machine:

DRINKS = (red->coffee->DRINKS| blue->tea->DRINKS).

F LTS generated using LTSA? F

F Possible traces? F

Page 62: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Example: Vending Machine

FSP model of a drinks machine:

DRINKS = (red->coffee->DRINKS| blue->tea->DRINKS).

F LTS generated using LTSA? F

F Possible traces? F

Page 63: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Non-Deterministic Choice

Process (x->P | x->Q) describes a process which engages in x andthen behaves as either P or Q.

COIN = (toss->HEADS | toss->TAILS),HEADS = (heads->COIN),TAILS = (tails->COIN).

Tossing a coin

F Possible traces? F

Page 64: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Non-Deterministic Choice

Process (x->P | x->Q) describes a process which engages in x andthen behaves as either P or Q.

COIN = (toss->HEADS | toss->TAILS),HEADS = (heads->COIN),TAILS = (tails->COIN).

Tossing a coin

F Possible traces? F

Page 65: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Indexed Processes and Actions

Single slot buffer that inputs a value in the range 0 to 3 and thenoutputs 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).

Page 66: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Indexed Processes and Actions

Single slot buffer that inputs a value in the range 0 to 3 and thenoutputs 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).

Page 67: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

or using a constant and indexed process BUFF[i]:

const N = 3BUFF = (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).

Page 68: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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 whenthe guard B is true.

Page 69: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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]).

Page 70: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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).

F LTS? F

Page 71: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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).

F LTS? F

Page 72: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Example: What is this?

F What is the following FSP process equivalent to? F

const False = 0

P = (when (False) doanything -> P).

Page 73: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Constant and Range Declarations

index expressions to model a calculation:

const N = 1range T = 0..Nrange R = 0..2*N

SUM = (in[a:T][b:T] -> TOTAL[a+b]),TOTAL[s:R] = (out[s] -> SUM).

F Write SUM using basic FSP? F

Page 74: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Constant and Range Declarations

index expressions to model a calculation:

const N = 1range T = 0..Nrange R = 0..2*N

SUM = (in[a:T][b:T] -> TOTAL[a+b]),TOTAL[s:R] = (out[s] -> SUM).

F Write SUM using basic FSP? F

Page 75: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Process Alphabets

• The alphabet of a process is the set of actions in which it isallowed to engage.

• This is usually determined implicitly as the actions in which itcan 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]}.

Page 76: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Outline

Topic 1: IntroductionGeneral BackgroundOn ConcurrencyExamplesImplementation

Topic 2: Modelling Processes with FSP - ILabelled Transition SystemsFSP: Basic ElementsSummary

Page 77: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

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]

Page 78: COMP30112: Concurrency - Introduction to Course ... › ~howard › Teaching › COMP30112 › Slides-08 › ...Implementation in Java • Thread class; Runnable interface • starting,

Topic 1: Introduction Topic 2: Modelling Processes with FSP - I

Process equation: process name = process expression

Process definition:

declarationsmain process equation,local process equation,

.

.

.local process equation,local process equation.