CSC321 §6 Modelling Processes using FSP 1 Section 6 Modelling Processes using FSP.

Slides:



Advertisements
Similar presentations
ICE1341 Programming Languages Spring 2005 Lecture #13 Lecture #13 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Advertisements

Expressions and Statements. 2 Contents Side effects: expressions and statements Expression notations Expression evaluation orders Conditional statements.
Concurrency: introduction1 ©Magee/Kramer 2 nd Edition Concurrency State Models and Java Programs Jeff Magee and Jeff Kramer.
Programming Paradigms for Concurrency Lecture 11 Part III – Message Passing Concurrency TexPoint fonts used in EMF. Read the TexPoint manual before you.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 Overview 7.1 Introduction to Arrays 7.2 Arrays in Functions 7.3.
Concurrency: safety & liveness properties1 ©Magee/Kramer 2 nd Edition COMP60611 Fundamentals of Parallel and Distributed Systems Lecture 14 Safety and.
 Control structures  Algorithm & flowchart  If statements  While statements.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 11: An introduction to CSP.
A Java API Package java.security  The Java Security Package contains classes and interfaces that are required by many Java programs.  This package is.
2. Java and Concurrency Prof. O. Nierstrasz Selected material © Magee and Kramer.
EECS 20 Chapter 3 Sections Defining Signals and Systems Last time we Found ways to define functions and systems Defined many example systems Today.
CP — Concurrent Programming 2. Java and Concurrency Prof. O. Nierstrasz Wintersemester 2005 / 2006.
Concurrency ©Magee/Kramer February 05, 2007 Claus Brabrand University of Aarhus Concurrency Spring 2007.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
Programming Control Flow. Sequential Program S1 S2 S5 S4 S3 int main() { Statement1; Statement2; … StatementN; } Start End.
Administrative MUST GO TO CORRECT LAB SECTION! Homework due 11:59pm on Tuesday. 25 points off if late (up to 24 hours) Cannot submit after 11:59pm on Wednesday.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Introduction to Programming G51PRG University of Nottingham Revision 2 Essam Eliwa.
Chapter 4 Statement Forms. Statement types 1.Simple statements expression; println(“The total is “ + total + “.”); (method call) 2. Compound statements.
Concurrency: shared objects & mutual exclusion1 ©Magee/Kramer 2 nd Edition Chapter 4 Shared Objects & Mutual Exclusion.
9/10/2015CS2104, Lecture 81 Programming Language Concepts, COSC Lecture 8 (Multiple) Threads Semantics.
Concurrency: introduction1 ©Magee/Kramer Concurrency State Models and Java Programs Jeff Magee and Jeff Kramer.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Programming C for Engineers An exercise is posted on the web site! Due in one week Single submission.
Concurrency: processes & threads1 ©Magee/Kramer Chapter 2 Processes & Threads.
Concurrency: introduction1 ©Magee/Kramer 2 nd Edition COMP60611 Fundamentals of Parallel and Distributed Systems Lecture 5 Introduction to Concurrency:
Object-Oriented Modeling Using UML CS 3331 Section 2.3 of Jia 2003.
© 2004 Pearson Addison-Wesley. All rights reserved February 20, 2006 ‘do’ and ‘for’ loops ComS 207: Programming I (in Java) Iowa State University, SPRING.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 5 Loops.
CS5204 – Operating Systems 1  -Calculus Reasoning about concurrency and communication (Part 1).
2015 Concurrency: processes & threads 1 ©Magee/Kramer 2 nd Edition Chapter 2 Processes & Threads.
CSC321 §6 Modelling Processes using FSP 1 Chapter 6 Modelling Processes using FSP.
Introduction to CSP Alexandre Mota
Internet Security CSCE 813 Communicating Sequential Processes.
Introduction to Java Java Translation Program Structure
Temporal Logic Model-checking with SPIN
Formal Methods for Software Engineering Part II: Modelling & Analysis of System Behaviour.
2015 Concurrency: logical properties 1 ©Magee/Kramer 2 nd Edition Chapter 14 Logical Properties Satisfied? Not satisfied?
Chapter 5 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved5-2 The switch Statement The switch statement provides another way.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
Traditionally ladder logic programs have been written by thinking about the process and then beginning to write the program. This always leads to programs.
55:032 - Intro. to Digital DesignPage 1 VHDL and Processes Defining Sequential Circuit Behavior.
1 Model-Checking of Component-Based Real-Time Embedded Software Based on CORBA Event Service Yuanfang Zhang for Seminar CSE7216 Presentation based on Zonghua.
Chapter 4 Statement Forms. Statement types 1.Simple statements expression; println(“The total is “ + total + “.”); (method call) 2. Compound statements.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
1 Theoretical Foundations of Concurrency A formal study of concurrency enables: understanding the essential nature of concurrency reasoning about the behavior.
Programming in Java (COP 2250) Lecture 12 & 13 Chengyong Yang Fall, 2005.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
Concurrency: processes & threads1 ©Magee/Kramer 2 nd Edition Chapter 2 Processes & Threads.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Formal Methods for Software Engineering
Definition of the Programming Language CPRL
Transition Graphs.
Finite State Machines Dr K R Bond 2009
Introduction To Flowcharting
Turing Machines Acceptors; Enumerators
MSIS 655 Advanced Business Applications Programming
3 Control Statements:.
Faculty of Computer Science & Information System
CSC312 Automata Theory Transition Graphs Lecture # 9
‘do’ and ‘for’ loops October 1, 2007 ComS 207: Programming I (in Java)
‘do’ and ‘for’ loops October 2, 2006 ComS 207: Programming I (in Java)
REPETITION Why Repetition?
Chapter 8 JavaScript: Control Statements, Part 2
Presentation transcript:

CSC321 §6 Modelling Processes using FSP 1 Section 6 Modelling Processes using FSP

CSC321 §6 Modelling Processes using FSP 2 Concurrent processes 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. Concept of a process as a sequence of actions.

CSC321 §6 Modelling Processes using FSP 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

CSC321 §6 Modelling Processes using FSP 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

CSC321 §6 Modelling Processes using FSP 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 on  off  on  off  on  off  ………. a sequence of actions or trace

CSC321 §6 Modelling Processes using FSP 6 FSP - action prefix If x is an action and P a process then (x-> P) describes a process that initially engages in the action x and then behaves exactly as described by P. ONESHOT = (once -> STOP). ONESHOT state machine (terminating process) Convention: actions begin with lowercase letters PROCESSES begin with uppercase letters

CSC321 §6 Modelling Processes using FSP 7 FSP - action prefix & recursion SWITCH = OFF, OFF = (on -> ON), ON = (off-> OFF). Repetitive behaviour uses recursion: Substituting to get a more succinct definition: SWITCH = OFF, OFF = (on ->(off->OFF)). And again: SWITCH = (on->off->SWITCH).

CSC321 §6 Modelling Processes using FSP 8 Animation using LTSA Ticked actions are eligible for selection. In the LTS, the last action is highlighted in red. The LTSA animator can be used to produce a trace.

CSC321 §6 Modelling Processes using FSP 9 FSP - action prefix TRAFFICLIGHT = (red->orange->green->orange -> TRAFFICLIGHT). LTS generated using LTSA: Trace: FSP model of a traffic light : red  orange  green  orange  red  orange  green …

CSC321 §6 Modelling Processes using FSP 10 FSP - 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 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?

CSC321 §6 Modelling Processes using FSP 11 FSP - choice DRINKS = (red->coffee->DRINKS |blue->tea->DRINKS ). LTS generated using LTSA: Possible traces? FSP model of a drinks machine :

CSC321 §6 Modelling Processes using FSP 12 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. Possible traces?

CSC321 §6 Modelling Processes using FSP 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->CHAN |in->out->CHAN ).

CSC321 §6 Modelling Processes using FSP 14 Single slot buffer that inputs a value in the range 0 to 3 and then outputs that value: FSP - indexed processes and actions BUFF = (in[i:0..3]->out[i]-> BUFF). equivalent to or using a process parameter with default value: BUFF = (in[0]->out[0]->BUFF |in[1]->out[1]->BUFF |in[2]->out[2]->BUFF |in[3]->out[3]->BUFF ). BUFF(N=3) = (in[i:0..N]->out[i]-> BUFF).

CSC321 §6 Modelling Processes using FSP 15 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). FSP - constant & range declaration index expressions to model calculation:

CSC321 §6 Modelling Processes using FSP 16 FSP - guarded actions The choice (when B x -> P | y -> 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 (N=3) = COUNT[0], COUNT[i:0..N] = (when(i COUNT[i+1] |when(i>0) dec->COUNT[i-1] ).

CSC321 §6 Modelling Processes using FSP 17 COUNT example COUNT = COUNT[0], COUNT[0] = (inc -> COUNT[1]), COUNT[1] = (inc -> COUNT[2] |dec -> COUNT[0]), COUNT[2] = (inc -> COUNT[3] |dec -> COUNT[1]), COUNT[3] = (dec -> COUNT[2]). COUNT (N=3) = COUNT[0], COUNT[i:0..N] = (when(i COUNT[i+1] |when(i>0) dec->COUNT[i-1] ).

CSC321 §6 Modelling Processes using FSP 18 public void run () { for (int i=0; i<20; i++) { if (RandomGenerator.integer(0,1)==0) inc(); else dec(); } class COUNT extends Thread { private int i; private int N=3; public COUNT(int i) { this.i=i; } public void inc() { if (i<N) i++; System.out.println("inc: i = "+i); } public void dec() { if (i>0) i--; System.out.println("dec: i = "+i); } COUNT example

CSC321 §6 Modelling Processes using FSP 19 FSP - guarded actions COUNTDOWN (N=3) = (start->COUNTDOWN[N]), COUNTDOWN[i:0..N] = (when(i>0) tick->COUNTDOWN[i-1] |when(i==0)beep->STOP |stop->STOP ). A countdown timer which beeps after N ticks, or can be stopped.

CSC321 §6 Modelling Processes using FSP 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 {write[0..3]} (we make use of alphabet extensions in later chapters) WRITER = (write[1]->write[3]->WRITER) +{write[0..3]}.

CSC321 §6 Modelling Processes using FSP 21 PERSON = (weekday -> sleep -> work -> PERSON |weekend -> sleep -> (shop -> PERSON |play -> PERSON) ). Exercises Give the FSP description of the LTS graph.

CSC321 §6 Modelling Processes using FSP 22 GAME = (one -> WIN |two -> WIN |three -> LOSE ), WIN = (win -> GAME), LOSE = (lose -> GAME). Exercises Give the FSP description of the LTS graph.

CSC321 §6 Modelling Processes using FSP 23 DOUBLE = (in[i:1..3] -> out[2*i] -> DOUBLE). Exercises Give the FSP description of the LTS graph.

CSC321 §6 Modelling Processes using FSP 24 FOURTICK = TICK[0], TICK[i:0..4] = (when (i TICK[i+1]). Exercises Give the FSP description of the LTS graph.

CSC321 §6 Modelling Processes using FSP 25 BISTABLE = ONE, ZERO = (trigger -> [0] -> ONE), ONE = (trigger -> [1] -> ZERO). Exercises