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

Models of Concurrency Manna, Pnueli.
Concurrent Programming Abstraction & Java Threads
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
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.
CSC321 §6 Modelling Processes using FSP 1 Section 6 Modelling Processes using FSP.
Programming Paradigms for Concurrency Lecture 11 Part III – Message Passing Concurrency TexPoint fonts used in EMF. Read the TexPoint manual before you.
Concurrency: safety & liveness properties1 ©Magee/Kramer 2 nd Edition COMP60611 Fundamentals of Parallel and Distributed Systems Lecture 14 Safety and.
1 CSC321 §2 Concurrent Programming Abstraction & Java Threads Section 2 Concurrent Programming Abstraction & Java Threads.
2. Java and Concurrency Prof. O. Nierstrasz Selected material © Magee and Kramer.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
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.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
50.003: Elements of Software Construction Week 5 Basics of Threads.
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.
Chapter 15 Multithreading F Threads Concept  Creating Threads by Extending the Thread class  Creating Threads by Implementing the Runnable Interface.
Java Programming: Advanced Topics
Concurrency: processes & threads1 ©Magee/Kramer Chapter 2 Processes & Threads.
Definitions & Scenarios. Acknowledgements  This tutorial is based in part on Concurrency: State Models & Java Programming by Jeff Magee and Jeff Kramer.
Concurrency: introduction1 ©Magee/Kramer 2 nd Edition COMP60611 Fundamentals of Parallel and Distributed Systems Lecture 5 Introduction to Concurrency:
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 19 : Recursion King Fahd University of Petroleum & Minerals College of Computer.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
111 © 2002, Cisco Systems, Inc. All rights reserved.
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.
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
2015 Concurrency: processes & threads 1 ©Magee/Kramer 2 nd Edition Chapter 2 Processes & Threads.
1 Web Based Programming Section 8 James King 12 August 2003.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
13-Nov-1513-Nov-1513-Nov-15 State Machines. What is a state machine? A state machine is a different way of thinking about computation A state machine.
Internet Security CSCE 813 Communicating Sequential Processes.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Formal Methods for Software Engineering Part II: Modelling & Analysis of System Behaviour.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Multithreading in JAVA
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Multi-Threading in Java
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 More on Thread API.
Multithreaded programming  Java provides built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Lecture 4 Introduction to Promela. Promela and Spin Promela - process meta language G. Holzmann, Bell Labs (Lucent) C-like language + concurrency dyamic.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
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.
Threads b A thread is a flow of control in a program. b The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.
Chapter 13: Multithreading The Thread class The Thread class The Runnable Interface The Runnable Interface Thread States Thread States Thread Priority.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
CSC321 §8 Implementing FSP Models in Java 1 Section 8 Implementing FSP Models in Java.
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
Multithreading / Concurrency
Chapter 13: Multithreading
Multithreaded Programming in Java
Introduction To Flowcharting
Electronics II Physics 3620 / 6620
Multithreading.
Multithreaded Programming
Basics of Recursion Programming with Recursion
Chapter 15 Multithreading
State Machines 6-Apr-196-Apr-19.
EPSII 59:006 Spring 2004.
Multithreading in java.
Threads and Multithreading
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

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

CSC321 §6 Modelling Processes using FSP 2 concurrent processes We structure complex systems as sets of simpler activities, each represented as a sequential process. Processes can overlap or be concurrent, so as to reflect the concurrency inherent in the physical world, or to offload time-consuming tasks, or to manage communications or other devices. 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 behavior. 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 Modeling 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 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 18 FSP - guarded actions What is the following FSP process equivalent to? const False = 0 P = (when (False) doanything->P). Answer: STOP

CSC321 §6 Modelling Processes using FSP 19 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 Implementing processes Modeling processes as finite state machines using FSP/LTS. Implementing threads in Java. Note: to avoid confusion, we use the term process when referring to the models, and thread when referring to the implementation in Java.

CSC321 §6 Modelling Processes using FSP 21 thread life-cycle in Java An overview of the life-cycle of a thread as state transitions: CreatedAlive Terminated new Thread() start() stop(), or run() returns stop() The predicate isAlive() can be used to test if a thread has been started but not terminated. Once terminated, it cannot be restarted (cf. mortals). start() causes the thread to call its run() method.

CSC321 §6 Modelling Processes using FSP 22 thread alive states in Java Once started, an alive thread has a number of substates : RunnableNon-Runnable suspend() resume() yield() Running dispatch suspend() start() stop(), or run() returns wait() also makes a Thread Non-Runnable, and notify() Runnable. sleep()

CSC321 §6 Modelling Processes using FSP 23 Java thread lifecycle - an FSP specification THREAD = CREATED, CREATED = (start ->RUNNING |stop ->TERMINATED), RUNNING = ({suspend,sleep}->NON_RUNNABLE |yield ->RUNNABLE |{stop,end} ->TERMINATED |run ->RUNNING), RUNNABLE = (suspend ->NON_RUNNABLE |dispatch ->RUNNING |stop ->TERMINATED), NON_RUNNABLE = (resume ->RUNNABLE |stop ->TERMINATED), TERMINATED = STOP.

CSC321 §6 Modelling Processes using FSP 24 Java thread lifecycle - an FSP specification end, run, dispatch are not methods of class Thread. States 0 to 4 correspond to CREATED, TERMINATED, RUNNING, NON-RUNNABLE, and RUNNABLE respectively.

CSC321 §6 Modelling Processes using FSP 25 CountDown timer example COUNTDOWN (N=3) = (start->COUNTDOWN[N]), COUNTDOWN[i:0..N] = (when(i>0) tick->COUNTDOWN[i-1] |when(i==0)beep->STOP |stop->STOP ). Implementation in Java?

CSC321 §6 Modelling Processes using FSP 26 CountDown class public class CountDown extends Applet implements Runnable { Thread counter; int i; final static int N = 10; AudioClip beepSound, tickSound; NumberCanvas display; public void init() {...} public void start() {...} public void stop() {...} public void run() {...} private void tick() {...} private void beep() {...} }

CSC321 §6 Modelling Processes using FSP 27 CountDown class - start(), stop() and run() public void start() { counter = new Thread(this); i = N; counter.start(); } public void stop() { counter = null; } public void run() { while(true) { if (counter == null) return; if (i>0) { tick(); --i; } if (i==0) { beep(); return;} } COUNTDOWN Model start -> stop -> COUNTDOWN[i] process recursion as a while loop STOP when(i>0) tick -> CD[i-1] when(i==0)beep -> STOP STOP when run() returns

CSC321 §6 Modelling Processes using FSP 28 Summary  Concepts process - unit of concurrency, execution of a program  Models LTS to model processes as state machines - sequences of atomic actions FSP to specify processes using prefix “->”, choice ” | ” and recursion.  Practice Java threads to implement processes. Thread lifecycle - created, running, runnable, non-runnable, terminated.