Book Chapter 2 - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Book Chapter 2

Description:

CSC321 6 Modelling Processes using FSP. 1. Section 6. Modelling Processes using FSP ... A countdown timer which beeps after N ticks, or can be stopped. ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 26
Provided by: jeffk59
Category:

less

Transcript and Presenter's Notes

Title: Book Chapter 2


1
Section 6
Modelling Processes using FSP
2
Concurrent processes
Concept of a process as a sequence of actions.
Designing concurrent software can be complex and
error prone. A rigorous engineering approach is
essential.
Model processes as finite state machines.
Program processes as threads in Java.
3
Processes and threads
Concepts processes - units of sequential
execution. Models finite state processes (FSP)
to model processes as
sequences of actions. labelled transition
systems (LTS) to analyse, display and animate
behaviour. Practice Java threads
4
6.1 Modeling Processes
Models are described using state machines, known
as Labelled Transition Systems LTS. These are
described textually as finite state processes
(FSP) and displayed and analysed by the LTSA
analysis tool.
  • LTS - graphical form
  • FSP - algebraic form

5
Modeling processes
A process is the execution of a sequential
program. It is modeled as a finite state machine
which transits from state to state by executing a
sequence of atomic actions.
a light switch LTS
a sequence of actions or trace
on?off?on?off?on?off? .
6
FSP - action prefix
If x is an action and P a process then (x-gt P)
describes a process that initially engages in the
action x and then behaves exactly as described by
P.
ONESHOT (once -gt STOP).
ONESHOT state machine (terminating process)
Convention actions begin with lowercase
letters PROCESSES begin with uppercase
letters
7
FSP - action prefix recursion
Repetitive behaviour uses recursion
SWITCH OFF, OFF (on -gt ON), ON
(off-gt OFF).
Substituting to get a more succinct definition
SWITCH OFF, OFF (on -gt(off-gtOFF)).
And again
SWITCH (on-gtoff-gtSWITCH).
8
Animation using LTSA
The LTSA animator can be used to produce a trace.
Ticked actions are eligible for selection. In the
LTS, the last action is highlighted in red.
9
FSP - action prefix
FSP model of a traffic light
TRAFFICLIGHT (red-gtorange-gtgreen-gtorange
-gt TRAFFICLIGHT).
LTS generated using LTSA
Trace
red?orange?green?orange?red?orange?green
10
FSP - choice
If x and y are actions then (x-gt P y-gt Q)
describes a process which initially engages in
either of the actions x or y. After the first
action has occurred, the subsequent behavior is
described by P if the first action was x and Q if
the first action was y.
Who or what makes the choice? Is there a
difference between input and output actions?
11
FSP - choice
FSP model of a drinks machine
DRINKS (red-gtcoffee-gtDRINKS
blue-gttea-gtDRINKS ).
LTS generated using LTSA
Possible traces?
12
Non-deterministic choice
Process (x-gt P x -gt Q) describes a process
which engages in x and then behaves as either P
or Q.
COIN (toss-gtHEADStoss-gtTAILS), HEADS
(heads-gtCOIN), TAILS (tails-gtCOIN).
Tossing a coin.
Possible traces?
13
Modelling failure
How do we model an unreliable communication
channel which accepts in actions and if a failure
occurs produces no output, otherwise performs an
out action? Use non-determinism...
CHAN (in-gtCHAN in-gtout-gtCHAN ).
14
FSP - indexed processes and actions
Single slot buffer that inputs a value in the
range 0 to 3 and then outputs that value
BUFF (ini0..3-gtouti-gt BUFF).
equivalent to
BUFF (in0-gtout0-gtBUFF
in1-gtout1-gtBUFF in2-gtout2-gtBUFF
in3-gtout3-gtBUFF ).
or using a process parameter with default value
BUFF(N3) (ini0..N-gtouti-gt BUFF).
15
FSP - constant range declaration
index expressions to model calculation
const N 1 range T 0..N range R 0..2N SUM
(inaTbT-gtTOTALab), TOTALsR
(outs-gtSUM).
16
FSP - guarded actions
The choice (when B x -gt P y -gt Q) means that
when the guard B is true then the actions x and y
are both eligible to be chosen, otherwise if B is
false then the action x cannot be chosen.
COUNT (N3) COUNT0, COUNTi0..N
(when(iltN) inc-gtCOUNTi1
when(igt0) dec-gtCOUNTi-1 ).
17
COUNT example
COUNT (N3) COUNT0, COUNTi0..N
(when(iltN) inc-gtCOUNTi1
when(igt0) dec-gtCOUNTi-1 ).
COUNT COUNT0, COUNT0 (inc -gt
COUNT1), COUNT1 (inc -gt COUNT2
dec -gt COUNT0), COUNT2 (inc -gt COUNT3
dec -gt COUNT1), COUNT3 (dec -gt
COUNT2).
18
COUNT example
public void run () for (int i0 ilt20
i) if (RandomGenerator.integer(0,1)0
) inc() else dec()

class COUNT extends Thread private int i
private int N3 public COUNT(int i)
this.ii public void inc()
if (iltN) i System.out.println("inc i
"i) public void dec() if
(igt0) i-- System.out.println("dec i
"i)
19
FSP - guarded actions
A countdown timer which beeps after N ticks, or
can be stopped.
COUNTDOWN (N3) (start-gtCOUNTDOWNN), COUNTDO
WNi0..N (when(igt0) tick-gtCOUNTDOWNi-1
when(i0)beep-gtSTOP stop-gtSTOP ).
20
FSP - process alphabets
The alphabet of a process is the set of actions
in which it can engage.
Alphabet extension can be used to extend the
implicit alphabet of a process Alphabet of
WRITER is the set write0..3 (we make use of
alphabet extensions in later chapters)
WRITER (write1-gtwrite3-gtWRITER)
write0..3.
21
Exercises
Give the FSP description of the LTS graph.
PERSON (weekday -gt sleep -gt work -gt PERSON
weekend -gt sleep -gt (shop -gt PERSON
play -gt PERSON) ).
22
Exercises
Give the FSP description of the LTS graph.
GAME (one -gt WIN two -gt WIN
three -gt LOSE ), WIN (win -gt
GAME), LOSE (lose -gt GAME).
23
Exercises
Give the FSP description of the LTS graph.
DOUBLE (ini1..3 -gt out2i -gt DOUBLE).
24
Exercises
Give the FSP description of the LTS graph.
FOURTICK TICK0, TICKi0..4 (when (ilt4)
tick -gt TICKi1).
25
Exercises
BISTABLE ONE, ZERO (trigger -gt 0 -gt
ONE), ONE (trigger -gt 1 -gt ZERO).
Write a Comment
User Comments (0)
About PowerShow.com