Introduction to Concurrency

Similar documents
Concurrency. State Models and Java Programs. Jeff Magee and Jeff Kramer. Concurrency: introduction 1. Magee/Kramer

Introduction to Concurrency. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 4 01/21/2010

Introduction to Concurrent Software Systems. CSCI 5828: Foundations of Software Engineering Lecture 08 09/17/2015

Introduction to Concurrent Software Systems. CSCI 5828: Foundations of Software Engineering Lecture 12 09/29/2016

CSCI 5828: Foundations of Software Engineering

CSCI 5828: Foundations of Software Engineering

SISTEMI CONCORRENTI E DI RETE LS II Facoltà di Ingegneria - Università di Bologna - Cesena - a.a / 2009 COURSE PRESENTATION

Specific Proposals for the Use of Petri Nets in a Concurrent Programming Course

Grand Central Dispatch and NSOperation. CSCI 5828: Foundations of Software Engineering Lecture 28 12/03/2015

Concurrency: State Models & Design Patterns

TIETS14 Introduction to Formal Specification

Learning-Based Assume-Guarantee Verification (Tool Paper)

Testing & Continuous Integration. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 20 03/19/2010

NETW3005 Operating Systems Lecture 1: Introduction and history of O/Ss

Chapter 8. Model-Based Design Concurrency: model-based design. Magee/Kramer 2 nd Edition

Concurrent processes. Processes and Threads. Processes and threads. Going back to Concurrency. Modelling Processes. Modeling processes

UNIVERSITY OF NEBRASKA AT OMAHA COURSE SYLLABUS/DESCRIPTION

Object Fundamentals. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 2 08/30/2007

Object Fundamentals, Part One. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 2 08/27/2009

Operating System Design

Frequently asked questions from the previous class survey

COSC243 Part 2: Operating Systems

Dealing with Bugs. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 27 04/21/2009

Module 5: Concurrent and Parallel Programming

Refactoring, Part 2. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 12/01/09. University of Colorado, 2009

Frequently asked questions from the previous class survey

Producing Production Quality Software. Lecture 12: Concurrent and Distributed Programming Prof. Arthur P. Goldberg Fall, 2004

MultiThreading. Object Orientated Programming in Java. Benjamin Kenwright

The Method for Verifying Software Architecture with FSP Model

CS110/CS119 Introduction to Computing (Java) Bob Wilson S-3-176

Design Approaches for Concurrent Systems. CSCI 5828: Foundations of Software Engineering Lecture 08 02/09/2012

18-642: Race Conditions

Good-Enough Design. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 11 02/17/2009

G52CON: Concepts of Concurrency

Finding Concurrency Bugs in Java

Distributed Systems Concepts Design 4th Edition

Distributed Systems Concepts Design 5th Edition Solutions

Lecture 15: I/O Devices & Drivers

Syllabus CSCI 405 Operating Systems Fall 2018

A Basic Snooping-Based Multi-Processor Implementation

CSC Operating Systems Fall Lecture - I Introduction. Tevfik Ko!ar. Louisiana State University. August 25 th, Contact Information

Learning from Bad Examples. CSCI 5828: Foundations of Software Engineering Lecture 25 11/18/2014

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

PROCESSES AND THREADS THREADING MODELS. CS124 Operating Systems Winter , Lecture 8

Program Analysis and Code Verification

CSCI 5828: Foundations of Software Engineering

CS153: Deadlock. Chengyu Song. Slides modified from Harsha Madhyvasta, Nael Abu-Ghazaleh, and Zhiyun Qian

Page 1. Human-computer interaction. Lecture 2: Design & Implementation. Building user interfaces. Users and limitations

CPSC 341 OS & Networks. Introduction. Dr. Yingwu Zhu

Implementing Architectures

Reintroduction to Concurrency

Administrivia. Events this week Drop-In Resume and Cover Letter Editing Date: Tues., Mar 23 Time: 12:30 2:30 pm Location: Rm 255, ICICS/CS

Prime Generating Algorithms by Skipping Composite Divisors

Kernels & Processes The Structure of the Operating System

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

1. Introduction to Model Checking

Page 1. Human-computer interaction. Lecture 1b: Design & Implementation. Building user interfaces. Mental & implementation models

Introduction In Practice State Explosion Problem Infinity and Uncomputability Techniques References. Model Checking. Toryn Qwyllyn Klassen

Concurrency: State Models & Design Patterns

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers

Unit 6 - Software Design and Development LESSON 1 INTRODUCTION

CS103 Lecture 1 Slides. Introduction Mark Redekopp

Processes & Threads. Concepts: processes - units of sequential execution.

Chapter 2. Processes & Threads. Concurrency: processes & threads 1. Magee/Kramer

San José State University Department of Computer Science CS 166 / SE 166, Information Security, Section 4, spring, 2017

Lecture 7 Deadlocks (chapter 7)

Credit where Credit is Due. Goals for this Lecture. Introduction to Design

EECS 482 Introduction to Operating Systems

Chapter 4: Threads. Operating System Concepts 8 th Edition,

GENERATING AND MODELING DATA FROM REAL-WORLD EXPERIMENTS

Dynamic Calculus Tools for Visualizing Calculus

COURSE OUTLINE Survey of Operating Systems

Extending the Spreadsheet to Illustrate Basic CPU Operations in a Computer Literacy Course

CS307: Operating Systems

JS Event Loop, Promises, Async Await etc. Slava Kim

Object Fundamentals Part Two. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009

SWE3004: Operating Systems. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CPS221 Lecture: Operating System Functions

CS1 Lecture 2 Jan. 16, 2019

CSCI 447 Operating Systems Filip Jagodzinski

ENCE 688R Civil Information Systems

Multimedia Programming with Java Getting Started

CALEDONIAN COLLEGE OF ENGINEERING, MODULE HANDBOOK. Department of Electrical & Computer Engineering SULTANATE OF OMAN. Module Code

CS307: Operating Systems

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

Lecture 7: Process & Thread Introduction

MANNING C CONCURRENCY IN ACTION SECOND EDITION

San José State University Department of Computer Science CS151, Section 04 Object Oriented Design Spring 2018

Parallel Programming in Distributed Systems Or Distributed Systems in Parallel Programming

I 3 I 2. ! Language of logic design " Logic optimization, state, timing, CAD tools

VALIDATION LED DEVELOPMENT OF OBJECT-ORIENTED SOFTWARE USING A MODEL VERIFIER

Teaching and Examination Scheme: PAPER HRS TH TU PR TH PR OR TW TOTAL

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

Survey #3. Final Exam. Today is totally optional! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings.

CS 307: Software Engineering. Lecture 10: Software Design and Architecture

Developing Applications for ios

JEFFERSON COLLEGE COURSE SYLLABUS ART170 GRAPHIC DESIGN II. 3 Credit Hours. Prepared by: Blake Carroll. Revised Date: January 2008 By: Nick Nihira

Lecture 2: Software Engineering (a review)

FREE JAVA TUTORIALS & GUIDE JAVA PROGRAMMING SOURCE CODE FREE JAVA COMPILERS AND JAVA PROGRAMMING - FREEBYTE'S GUIDE TO

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012

Transcription:

Introduction to Concurrency Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 3 01/22/2008 University of Colorado, 2008 1

Credit where Credit is Due Some text and images for this lecture come from the lecture materials provided by the publisher of the Magee/Kramer textbook. As such, some material is copyright 2006 John Wiley & Sons, Ltd. 2

Lecture Goals Review material in Chapter 1 of the Magee/Kramer book What do we mean by concurrent programs? What do we mean by model-based software engineering? Examine fundamental approach used in this book: Concepts, Modeling, Practice 3

More on the Authors: The Two Jeffs Jeff Kramer Dean of the Faculty of Engineering and Professor of Distributed Computing at the Department of Computing at Imperial College London ACM Fellow Editor of IEEE s Transactions on Software Engineering Winner of numerous software engineering awards including best paper and outstanding research awards Jeff Magee Professor at the Department of Computing at Imperial College London Long time member of the SE community with more than 70 journal and conference publications! This book s material is based on their SE research into modeling concurrency over the past 20 years 4

What is a Concurrent Program? When we execute a program, we create a process A sequential program has a single thread of control A concurrent program has multiple threads of control A single computer can have multiple processes running at once If that machine, has a single processor, then the illusion of multiple processes running at once is just that: an illusion That illusion is maintained by the operating system that coordinates access to the single processor among the various processes If a machine has more than a single processor, then true parallelism can occur: you can have N processes running simultaneously on a machine with N processors 5

Another View: Sequential Program 8 1 4 7 9 6 baz.java main.java foo.java 2 3 5 db.java ui.java bar.java 6

Another View: Concurrent Program 8 1 4 7 9 2 6 3 baz.java main.java foo.java 2 3 5 4 1 5 db.java ui.java bar.java 7

Expanding the Definition As we ll see later in the semester, the definition of program is expanding In particular, its no longer true that single program = single process A single logical programs can follow any of these patterns these days single process, single thread, single machine (single core or multi-core) single process, multiple threads, single machine multi-process, single threaded, single or multiple machines multi-process, multi-threaded, single or multiple machines Concurrent programs can perform multiple computations in parallel and can control multiple external activities which occur at the same time A key difficulty with dealing with programming concurrent programs is dealing with interactions between threads or processes 8

Concurrent and Distributed Software? Communication Network Interacting, concurrent software components of a system: single machine shared memory interactions the value of a shared variable can become meaningless if updated by multiple threads simultaneously (without some form of control) multiple machines network interactions 9

Why Concurrent Programming? Performance gain from multi-core hardware True 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 by partitioning the application s thread/process structure to match its external conditions (e.g. one thread per activity) 10

Concurrent Programming: Hard to Ignore Multi-core chips are becoming widely deployed Only multi-threaded applications will see the performance benefits that these chips offer Programming for the Web often requires concurrent programming AJAX Web browsers are examples of multi-threaded GUI applications without threads the UI would block as information is downloaded Lots of other domains in which concurrency is the norm Embedded software systems, robotics, command-and-control, 11

BUT While concurrency is widespread it is also error prone Programmers trained on single-threaded programs face unfamiliar problems: synchronization, race conditions, deadlocks, etc. Example: Therac-25 Concurrent programming errors contributed to accidents causing death and serious injury Mars Rover Problems with interaction between concurrent tasks caused periodic software resets reducing availability for exploration 12

Cruise Control System Requirements Controlled by three buttons on, off, resume When ignition is switched on and on button pressed, current speed is recorded and system maintains the speed of the car at the recorded setting Two Threads: Engine and Control Once implemented: Is the system safe? Would testing reveal all errors? How many paths through system? Pressing the brake, the accelerator, or the off button disables the system Pressing resume re-enables the system 13

Models to the Rescue! The answer to our questions on the previous slide is to construct a model of the concurrent behavior of the system and then analyze the model This is one benefit of models, they focus on one particular aspect of the world and ignore all others Consider the model on the front of the Concurrency book The picture shows the image of a real-world train next to its model Depending on the model, you can ask certain questions and get answers that reflect the answers you would get if you asked the real system For the train model, you might be able to ask What color is the train? How long is it? How many cars does it have? But not What s the train s maximum speed? How does it behave when a car derails? 14

Models, continued In summary, a model is a simplified representation of the real world A model airplane, e.g., used in wind tunnels models only the external shape of the airplane The reduction in scale and complexity achieved by modeling allows engineers to analyze properties of the model The earliest models were physical (like our model train) modern models tend to be mathematical and are analyzed by computers Engineers use models to gain confidence in the adequacy and validity of a proposed design focus on an aspect of interest concurrency can animate model to visualize a behavior can analyze model to verify properties 15

Models for Concurrency When modeling concurrency, we make use of a type of finite state machine known as a labeled transition system or LTS These machines are described textually with a specification language called finite state processes (FSP) These machines can be displayed and analyzed by an analysis tool called LTSA Note: LTSA requires a Java 2 run time system, version 1.5.0 or later On Windows and Mac OS systems, you can run the LTSA tool by double clicking on its jar file Note: Its not the most intuitive piece of software, but once you grok it, it provides all of the advertised functionality 16

Modeling the Cruise Control System We won t model the entire system, lets look at a simplified example Given the following specification CRUISE = (engineon -> RUNNING), RUNNING = (speed -> RUNNING engineoff -> CRUISE). We can generate a finite state machine that looks like this 17

LTSA LTSA allows us to enter specifications and generate state machines like the ones on the previous slide It can also be used to animate or step through the state machine Lets see a demo Note: animation at left shows the problem we encountered before with the cruise control system 18

LTSA, continued Using a modeling tool, like LTSA, allows us to understand the concurrent behaviors of systems, like the cruise control system, BEFORE they are implemented This can save a lot of time and money, as it is typically easier to test and evolve a model's behavior than it is to implement the system in a programming language 19

Applying Concepts/Models via Programming Textbook makes use of Java to enable practice of these concepts Java is widely available, generally accepted, and portable provides sound set of concurrency features Java is used for all examples, demo programs, and homework exercises in textbook This is not to say that Java is the ONLY language that supports concurrency; many languages have concurrency feature built-in or available via third-party libraries The book makes use of toy programs as they can focus quickly on a particular class of concurrent behavior 20

Wrapping Up Concepts We adopt a model-based approach for the design and construction of concurrent programs Models We use finite state machines to represent concurrent behavior Practice We use Java for constructing concurrent programs We will be presenting numerous examples to illustrate concepts, models and demonstration programs 21

Coming Up Next Lecture 4: Processes and Threads Chapter 2 of Magee and Kramer Lecture 5: Modeling the Process and Life Cycle Chapter 2 of Pfleeger and Atlee 22