Introduction to Concurrency Principles of Concurrent System Design

Similar documents
Shared Mutable State SWEN-220

Parallel Programming with OpenMP

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

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

Threads and Locks. CSCI 5828: Foundations of Software Engineering Lecture 09 09/22/2015

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

Concurrency: Past and Present

CSE 374 Programming Concepts & Tools

Lecture 27: Safety and Liveness Properties, Java Synchronizers, Dining Philosophers Problem

Software Architecture and Engineering Introduction Peter Müller

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

Concurrent Programming Synchronisation. CISTER Summer Internship 2017

Safety SPL/2010 SPL/20 1

Concurrent Programming

Thread Safety. Review. Today o Confinement o Threadsafe datatypes Required reading. Concurrency Wrapper Collections

Program Validation and Testing

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

CS 450 Exam 2 Mon. 11/7/2016

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

Concurrent Programming

The New Java Technology Memory Model

Concurrent Programming in C++ Venkat

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Synchronization. Announcements. Concurrent Programs. Race Conditions. Race Conditions 11/9/17. Purpose of this lecture. A8 released today, Due: 11/21

Principles of Software Construction: Objects, Design, and Concurrency. The Perils of Concurrency Can't live with it. Cant live without it.

THREADS AND CONCURRENCY

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

Course Details. Operating Systems with C/C++ Course Details. What is an Operating System?

Synchronization in Concurrent Programming. Amit Gupta

THREADS & CONCURRENCY

Algorithmic Verification. Algorithmic Verification. Model checking. Algorithmic verification. The software crisis (and hardware as well)

Executive Summary. It is important for a Java Programmer to understand the power and limitations of concurrent programming in Java using threads.

Concurrency. Glossary

Java s Implementation of Concurrency, and how to use it in our applications.

Message Passing. Advanced Operating Systems Tutorial 7

Concurrency and High Performance Reloaded

Synchronization SPL/2010 SPL/20 1

Synchronization Lecture 23 Fall 2017

18-642: Race Conditions

COMP 346 Winter 2019 Programming Assignment 2

Agenda. Highlight issues with multi threaded programming Introduce thread synchronization primitives Introduce thread safe collections

Module 5: Concurrent and Parallel Programming

Dealing with Issues for Interprocess Communication

Contribution:javaMultithreading Multithreading Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team

11/19/2013. Imperative programs

What is uop Cracking?

Parallel Programming: Background Information

Parallel Programming: Background Information

Results of prelim 2 on Piazza

The Actor Model. Towards Better Concurrency. By: Dror Bereznitsky

CMSC 132: Object-Oriented Programming II. Threads in Java

CMSC 433 Programming Language Technologies and Paradigms. Concurrency

THREADS & CONCURRENCY

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

Parallelism Marco Serafini

a. A binary semaphore takes on numerical values 0 and 1 only. b. An atomic operation is a machine instruction or a sequence of instructions

Operating Systems. Lecture Course in Autumn Term 2015 University of Birmingham. Eike Ritter. September 22, 2015

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

Unit Testing in Java with an Emphasis on Concurrency Corky Cartwright Rice and Halmstad Universities Summer 2013

CS 261 Fall Mike Lam, Professor. Threads

Formal Methods in Practice: Tools and Examples

Distributed Systems. coordination Johan Montelius ID2201. Distributed Systems ID2201

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

System Software. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 13

CS5460: Operating Systems

Administrivia. Talks and other opportunities: Expect HW on functions in ASM (printing binary trees) soon

Announcements. Operating Systems. Autumn CS4023

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

So far, we know: Wednesday, October 4, Thread_Programming Page 1

Parallelism. Parallel Hardware. Introduction to Computer Systems

Systems, Networks & Concurrency Uwe R. Zimmer - The Australian National University

Sharing Objects Ch. 3

Synchronization Lecture 24 Fall 2018

Last week, David Terei lectured about the compilation pipeline which is responsible for producing the executable binaries of the Haskell code you

CS510 Operating System Foundations. Jonathan Walpole

G52CON: Concepts of Concurrency

Concurrency and Parallel Computing. Ric Glassey

Why do we care about parallel?

Chapter 4: Processes. Process Concept

Atomicity via Source-to-Source Translation

Threads SPL/2010 SPL/20 1

Chapter 4: Processes

Threads and Concurrency in Java

The Java Memory Model

Working With Ruby Threads. Copyright (C) 2013 Jesse Storimer. This book is dedicated to Sara, Inara, and Ora, who make it all worthwhile.

Unit 1: Introduction

Design of Parallel Algorithms. Course Introduction

Announcements. Cond Var: Review

Recap. Contents. Reenterancy of synchronized. Explicit Locks: ReentrantLock. Reenterancy of synchronise (ctd) Advanced Thread programming.

Race Conditions & Synchronization

Multithreaded Programming Part II. CSE 219 Stony Brook University, Department of Computer Science

Concurrent Preliminaries

Operating Systems: Quiz2 December 15, Class: No. Name:

Synchronising Threads

Dining Philosophers, Semaphores

The Various Faces of the.net Task Parallel Library

<Insert Picture Here> Implementing lambda expressions in Java

When Embedded Systems Attack. Unit 22. Therac-25. Therac-25. Embedded Failures. Embedded systems can fail for a variety of reasons

Paradigmas de Computação Paralela

Curriculum 2013 Knowledge Units Pertaining to PDC

Transcription:

Introduction to Concurrency 4010-441 Principles of Concurrent System Design

Texts Logistics (On mycourses) Java Concurrency in Practice, Brian Goetz, et. al. Programming Concurrency on the JVM, Venkat Subramaniam. Rough Calendar 4 weeks on controlling shared, mutable state + 1 exam + project 2 weeks on actors + 1 exam + project 1.5 weeks on (software) transactional memory 1.5 weeks on classic concurrency problems 1 week on other approaches to concurrency

Grading (5%) Preparation & Presentation (15%) Activities (2-3 persons for a week or less) (30%) Two projects (15% lowest each) (30%) Two in-class exams (15% each) (20%) Final exam in finals week

4-5 persons for 2+ weeks I'll pick the teams Projects You'll have an opportunity to assess the contributions of your teammates via Peer2Peer. Individual grade is team grade, adjusted as appropriate based on peer evaluations. Activities 2-3 persons for <= 1 week I'll pick the teams - sub-teams of projects where feasible Always traded on a 10 point basis

Preparation & Participation Do the readings before the specified due date I'll consider participation in answering questions and engaging in discussions. In participating in discussions, I will never penalize you for a wrong answer (unless you're flippant). Woody Allen: 80% of success is showing up.

Now on to the good stuff!

What Is "Concurrency?"

What Is "Concurrency?" What Is a Process?

What Is "Concurrency? What Is a Process? What Is a Thread?

What Is Concurrency? Two events are said to be concurrent if they occur within the same time interval. Two or more tasks executing over the same time interval are said to execute concurrently. In concurrent programming, there are two basic units of execution: processes and threads. What Is a Process? What Is a Thread?

What Is "Concurrency? Two events are said to be concurrent if they occur within the same time interval. Two or more tasks executing over the same time interval are said to execute concurrently. In concurrent programming, there are two basic units of execution: processes and threads. What Is a Process? A process has a self-contained execution environment. A process generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space. What Is a Thread?

What Is "Concurrency? Two events are said to be concurrent if they occur within the same time interval. Two or more tasks executing over the same time interval are said to execute concurrently. In concurrent programming, there are two basic units of execution: processes and threads. What Is a Process? A process has a self-contained execution environment. A process generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space. What Is a Thread? Threads exist within a process every process has at least one. Threads share the process's resources, including memory and open files. This makes for efficient, but potentially problematic, communication.

The Promises of Concurrency Original (OS centric processes) Better resource utilization. Fairness among multiple users with multiple computations.

The Promises of Concurrency Original (OS centric processes) Better resource utilization. Fairness among multiple users with multiple computations. Current (process centric threads) Exploiting multiple processors Moore's Law running out of steam (multi-core). Modeling: Divide & conquer on loosely related tasks. Simplify handling asynchronicity (e.g., mouse events) Throughput (even on single CPU systems) Responsiveness

Safety: Nothing bad happens The Perils of Concurrency Incorrect behavior in context of concurrency Race conditions Memory barrier (caching) Overly optimistic compiler optimizations

Safety: Nothing bad happens The Perils of Concurrency Incorrect behavior in context of concurrency Race conditions Memory barrier (caching) Overly optimistic compiler optimizations Liveness: Good things eventually happen One or more threads cannot make progress Deadlock

Safety: Nothing bad happens The Perils of Concurrency Incorrect behavior in context of concurrency Race conditions Memory barrier (caching) Overly optimistic compiler optimizations Liveness: Good things eventually happen One or more threads cannot make progress Deadlock Fairness: Let's share, boys and girls Starvation Livelock

Safety: Nothing bad happens The Perils of Concurrency Incorrect behavior in context of concurrency Race conditions Memory barrier (caching) Overly optimistic compiler optimizations Liveness: Good things eventually happen One or more threads cannot make progress Deadlock Fairness: Let's share, boys and girls Starvation Livelock Performance TANSTAAFL (There Ain t No Such Thing As A Free Lunch) Context switching overhead Disabled compiler optimizations

Safety: Nothing bad happens The Perils of Concurrency Incorrect behavior in context of concurrency Race conditions Memory barrier (caching) Overly optimistic compiler optimizations Liveness: Good things eventually happen One or more threads cannot make progress Deadlock Fairness: Let's share, boys and girls Starvation Livelock Performance TANSTAAFL Context switching overhead Disabled compiler optimizations Testing, hair-pulling, and Heisenbugs

The Perils of Concurrency 1985-1987 -- Therac-25 medical accelerator. A radiation therapy device malfunctions and delivers lethal radiation doses at several medical facilities. Based upon a previous design, the Therac-25 was an "improved" therapy system that could deliver two different kinds of radiation: either a low-power electron beam (beta particles) or X-rays. The Therac-25's X-rays were generated by smashing high-power electrons into a metal target positioned between the electron gun and the patient. A second "improvement" was the replacement of the older Therac-20's electromechanical safety interlocks with software control, a decision made because software was perceived to be more reliable. What engineers didn't know was that both the 20 and the 25 were built upon an operating system that had been kludged together by a programmer with no formal training. Because of a subtle bug called a "race condition," a quick-fingered typist could accidentally configure the Therac-25 so the electron beam would fire in high-power mode but with the metal X-ray target out of position. At least five patients die; others are seriously injured. (Source: History's Worst Software Bugs, Wired)

The Ultimate Culprit - Shared, Mutable State Most of your development has been in imperative languages. The fundamental operation is assignment to change state. Assignable variables are mutable. May be exposed as public (bad karma). May be exposed via interface methods (medium warm karma). Things get tricky very fast when > 1 thread can invoke a mutating function.

The Ultimate Culprit - Shared, Mutable State Most of your development has been in imperative languages. The fundamental operation is assignment to change state. Assignable variables are mutable. May be exposed as public (bad karma). May be exposed via interface methods (medium warm karma). Things get tricky very fast when > 1 thread can invoke a mutating function. public class Counter { private int count = 0 ; public void increment() { count = count + 1 ; } If we call increment() 10,000 times and then call getcount(), what value is returned? } public int getcount() { return count ; }

The Ultimate Culprit - Shared, Mutable State Most of your development has been in imperative languages. The fundamental operation is assignment to change state. Assignable variables are mutable. May be exposed as public (bad karma). May be exposed via interface methods (medium warm karma). Things get tricky very fast when > 1 thread can invoke a mutating function. Three basic approaches: Make things immutable. Hide shared state behind sequential access. Provide mechanisms to support controlled access to shared, mutable state.

Thread management Other Issues How many threads at one time? Allocation of tasks to threads. Thread scheduling. Higher level constructs Fork / join Callables & Futures Distributed state management State consistency Decision consensus