Concurrency: introduction1 ©Magee/Kramer 2 nd Edition COMP60611 Fundamentals of Parallel and Distributed Systems Lecture 5 Introduction to Concurrency:

Slides:



Advertisements
Similar presentations
CSC321 §1 Concurrent Programming 1 CSC 321 Concurrent Programming Course web site
Advertisements

Lecture 8: Three-Level Architectures CS 344R: Robotics Benjamin Kuipers.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
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.
Concurrency: monitors & condition synchronization1 ©Magee/Kramer 2 nd Edition COMP60611 Fundamentals of Parallel and Distributed Systems Lecture 8b Monitors.
Concurrency: safety & liveness properties1 ©Magee/Kramer 2 nd Edition COMP60611 Fundamentals of Parallel and Distributed Systems Lecture 14 Safety and.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 11: An introduction to CSP.
Concurrency ©Magee/Kramer February 05, 2007 Claus Brabrand University of Aarhus Concurrency Spring 2007.
1: Operating Systems Overview
© 2005 Prentice Hall12-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
Software Engineering, COMP201 Slide 1 Protocol Engineering Protocol Specification using CFSM model Lecture 30.
©Ian Sommerville 2000Software Engineering, 6/e, Chapter 91 Formal Specification l Techniques for the unambiguous specification of software.
CprE 458/558: Real-Time Systems
Chapter 1 Program Design
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 10 Slide 1 Formal Specification.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 10 Slide 1 Critical Systems Specification 3 Formal Specification.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 10 Slide 1 Formal Specification.
What is Concurrent Programming? Maram Bani Younes.
Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and.
Concurrency: introduction1 ©Magee/Kramer Concurrency State Models and Java Programs Jeff Magee and Jeff Kramer.
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 9 Slide 1 Formal Specification l Techniques for the unambiguous specification of software.
LOGO OPERATING SYSTEM Dalia AL-Dabbagh
Operating System Review September 10, 2012Introduction to Computer Security ©2004 Matt Bishop Slide #1-1.
The Architecture of Secure Systems Jim Alves-Foss Laboratory for Applied Logic Department of Computer Science University of Idaho By, Nagaashwini Katta.
Chapter 1 What is Programming? Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Benjamin Gamble. What is Time?  Can mean many different things to a computer Dynamic Equation Variable System State 2.
Scientific Computing By: Fatima Hallak To: Dr. Guy Tel-Zur.
Concurrency: processes & threads1 ©Magee/Kramer Chapter 2 Processes & Threads.
EEL Software development for real-time engineering systems.
1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 16 th, 2010 The University of Georgia.
Object-Oriented Modeling Using UML CS 3331 Section 2.3 of Jia 2003.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
- 1 - Embedded Systems - SDL Some general properties of languages 1. Synchronous vs. asynchronous languages Description of several processes in many languages.
WXGE6103 Software Engineering Process and Practice Formal Specification.
2015 Concurrency: model-based design 1 ©Magee/Kramer 2 nd Edition Chapter 8 Model-Based Design.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Ch. 2. Specification and Modeling 2.1 Requirements Describe requirements and approaches for specifying and modeling embedded systems. Specification for.
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.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 22 Slide 1 Software Verification, Validation and Testing.
Introduction to CSP Alexandre Mota
1 Qualitative Reasoning of Distributed Object Design Nima Kaveh & Wolfgang Emmerich Software Systems Engineering Dept. Computer Science University College.
Internet Security CSCE 813 Communicating Sequential Processes.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Formal Methods for Software Engineering Part II: Modelling & Analysis of System Behaviour.
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
2015 Concurrency: logical properties 1 ©Magee/Kramer 2 nd Edition Chapter 14 Logical Properties Satisfied? Not satisfied?
Modelling Reactive Systems 4 Professor Muffy Calder Dept. of Computing Science University of Glasgow
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
CS223: Software Engineering
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Software Systems Verification and Validation Laboratory Assignment 4 Model checking Assignment date: Lab 4 Delivery date: Lab 4, 5.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
1 Model-Checking of Component-Based Real-Time Embedded Software Based on CORBA Event Service Yuanfang Zhang for Seminar CSE7216 Presentation based on Zonghua.
Agenda  Quick Review  Finish Introduction  Java Threads.
Concurrency: processes & threads1 ©Magee/Kramer 2 nd Edition Chapter 2 Processes & Threads.
Computer Systems Architecture Edited by Original lecture by Ian Sunley Areas: Computer users Basic topics What is a computer?
Concepts, Models and Programs Jeff Kramer and Jeff Magee
Formal Methods for Software Engineering
Software Engineering with Reusable Components
Process Description and Control
COMP60621 Fundamentals of Parallel and Distributed Systems
Concurrency: Mutual Exclusion and Process Synchronization
Process Description and Control
COMP60611 Fundamentals of Parallel and Distributed Systems
Presentation transcript:

Concurrency: introduction1 ©Magee/Kramer 2 nd Edition COMP60611 Fundamentals of Parallel and Distributed Systems Lecture 5 Introduction to Concurrency: FSP Len Freeman, Graham Riley Centre for Novel Computing School of Computer Science University of Manchester

Concurrency: introduction2 ©Magee/Kramer 2 nd Edition Concurrency State Models and Java Programs Jeff Magee and Jeff Kramer ++ (but using C not Java)

Concurrency: introduction3 ©Magee/Kramer 2 nd Edition What is a Concurrent Program? A sequential program has a single thread of control. A concurrent program has multiple threads of control allowing it perform multiple computations in parallel and to control multiple external activities which occur at the same time.

Concurrency: introduction4 ©Magee/Kramer 2 nd Edition Concurrent and Distributed Software? Interacting, concurrent software components of a system: single machine -> shared memory interactions multiple machines -> network interactions

Concurrency: introduction5 ©Magee/Kramer 2 nd Edition Why Concurrent Programming?  Performance gain from multiprocessing hardware parallelism.  Increased application throughput an I/O call need only block one thread.  Increased application responsiveness high priority thread for user requests.  More appropriate structure for programs which interact with the environment, control multiple activities and handle multiple events.

Concurrency: introduction6 ©Magee/Kramer 2 nd Edition Do I need to know about concurrent programming?  Therac - 25 computerised radiation therapy machine Concurrent programming errors contributed to accidents causing deaths and serious injuries.  Mars Rover Problems with interaction between concurrent tasks caused periodic software resets reducing availability for exploration. Concurrency is widespread but error prone.

Concurrency: introduction7 ©Magee/Kramer 2 nd Edition a Cruise Control System  Is the system safe?  Would testing be sufficient to discover all errors? When the car ignition is switched on and the on button is pressed, the current speed is recorded and the system is enabled: it maintains the speed of the car at the recorded setting. Pressing the brake, accelerator or off button disables the system. Pressing resume re-enables the system. buttons

Concurrency: introduction8 ©Magee/Kramer 2 nd Edition models A model is a simplified representation of the real world. Engineers use models to gain confidence in the adequacy and validity of a proposed design.  focus on an aspect of interest - concurrency  mechanical verification of properties (safety & progress) 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.

Concurrency: introduction9 ©Magee/Kramer 2 nd Edition modeling the Cruise Control System Later chapters will explain how to construct models such as this so as to perform animation and verification. LTS of the process that monitors speed. LTSA Animator to step through system actions and events.

Concurrency: introduction10 ©Magee/Kramer 2 nd Edition programming practice in C and pthreads (and some MPI) C and pthreads are  widely available, generally accepted and portable  provides sound set of concurrency features “Toy” problems are also used as they exemplify particular aspects of concurrent programming problems!

Concurrency: introduction11 ©Magee/Kramer 2 nd Edition course objective This course is intended to provide a sound understanding of the concepts, models and practice involved in designing concurrent software. The emphasis on principles and concepts provides a thorough understanding of both the problems and the solution techniques. Modeling provides insight into concurrent behavior and aids reasoning about particular designs. Concurrent programming in C and pthreads provides the programming practice and experience.

Concurrency: introduction12 ©Magee/Kramer 2 nd Edition Book Concurrency: State Models & Java Programs, 2 nd Edition Jeff Magee & Jeff Kramer WILEY 1 st edition

Concurrency: introduction13 ©Magee/Kramer 2 nd Edition Course Outline 2. Processes and Threads 3. Concurrent Execution 4. Shared Objects & Interference 5. Monitors & Condition Synchronization 6. Deadlock 7. Safety and Liveness Properties 8. Model-based Design 9.Dynamic systems 10. Message Passing 11. Concurrent Software Architectures Concepts Models Practice 12. Timed Systems 13. Program Verification 14. Logical Properties The main basic Advanced topics …

Concurrency: introduction14 ©Magee/Kramer 2 nd Edition Web based course material  Java examples and demonstration programs  State models for the examples  Labelled Transition System Analyser (LTSA) for modeling concurrency, model animation and model property checking.

Concurrency: introduction15 ©Magee/Kramer 2 nd Edition Summary  Concepts we adopt a model-based approach for the design and construction of concurrent programs  Models we use finite state models to represent concurrent behavior.  Practice we use C and pthreads for constructing concurrent programs. Examples are used to illustrate the concepts, models and demonstration programs.

Concurrency: introduction16 ©Magee/Kramer 2 nd Edition Chapter 2 Processes & Threads

Concurrency: introduction17 ©Magee/Kramer 2 nd Edition 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 C or (Unix) Processes in MPI. Concept of a process as a sequence of actions.

Concurrency: introduction18 ©Magee/Kramer 2 nd Edition 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 : C and threads

Concurrency: introduction19 ©Magee/Kramer 2 nd Edition 2.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

Concurrency: introduction20 ©Magee/Kramer 2 nd Edition 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 Can finite state models produce infinite traces?

Concurrency: introduction21 ©Magee/Kramer 2 nd Edition 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

Concurrency: introduction22 ©Magee/Kramer 2 nd Edition 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).

Concurrency: introduction23 ©Magee/Kramer 2 nd Edition 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.

Concurrency: introduction24 ©Magee/Kramer 2 nd Edition 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 …

Concurrency: introduction25 ©Magee/Kramer 2 nd Edition 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?

Concurrency: introduction26 ©Magee/Kramer 2 nd Edition FSP - choice DRINKS = (red->coffee->DRINKS |blue->tea->DRINKS ). LTS generated using LTSA: Possible traces? FSP model of a drinks machine :

Concurrency: introduction27 ©Magee/Kramer 2 nd Edition 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?

Concurrency: introduction28 ©Magee/Kramer 2 nd Edition 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 ).

Concurrency: introduction29 ©Magee/Kramer 2 nd Edition 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). indexed actions generate labels of the form action. index

Concurrency: introduction30 ©Magee/Kramer 2 nd Edition 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). index expressions to model calculation: FSP - indexed processes and actions Local indexed process definitions are equivalent to process definitions for each index value

Concurrency: introduction31 ©Magee/Kramer 2 nd Edition 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] ).

Concurrency: introduction32 ©Magee/Kramer 2 nd Edition 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.

Concurrency: introduction33 ©Magee/Kramer 2 nd Edition FSP - guarded actions What is the following FSP process equivalent to? const False = 0 P = (when (False) doanything->P). Answer: STOP

Concurrency: introduction34 ©Magee/Kramer 2 nd Edition FSP - process alphabets The alphabet of a process is the set of actions in which it can engage. Process alphabets are implicitly defined by the actions in the process definition. The alphabet of a process can be displayed using the LTSA alphabet window. Process: COUNTDOWN Alphabet: { beep, start, stop, tick }

Concurrency: introduction35 ©Magee/Kramer 2 nd Edition FSP - process alphabet extension 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]}.

Concurrency: introduction36 ©Magee/Kramer 2 nd Edition Revision & Wake-up Exercise In FSP, model a process FILTER, that exhibits the following repetitive behavior: inputs a value v between 0 and 5, but only outputs it if v <= 2, otherwise it discards it. FILTER = (in[v:0..5] -> DECIDE[v]), DECIDE[v:0..5] = ( ? ).

Concurrency: introduction37 ©Magee/Kramer 2 nd Edition 2.2 Implementing processes Modeling processes as finite state machines using FSP/LTS. Implementing threads in C and pthreads (and MPI). Note: to avoid confusion, we use the term process when referring to the models, and thread when referring to the implementation in C.

Concurrency: introduction38 ©Magee/Kramer 2 nd Edition 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 C and pthreads to implement processes.