The Problem with Treads

Similar documents
The Problem with Threads

Understandable Concurrency

Concurrent programming is difficult,1 yet many

Concurrency & Multithreading

Concurrent Semantics without the Notions of State or State Transitions

fakultät für informatik informatik 12 technische universität dortmund Specifications Peter Marwedel TU Dortmund, Informatik /11/15

Concurrent Models of Computation

Concurrency Demands New Foundations for Computing

Making Concurrency Mainstream

Introduction to Embedded Systems

Specifications and Modeling

SCCharts. Sequentially Constructive Charts

Disciplined Concurrent Models of Computation for Parallel Software

Concurrent Models of Computation

EE382N.23: Embedded System Design and Modeling

Future Directions. Edward A. Lee. Berkeley, CA May 12, A New Computational Platform: Ubiquitous Networked Embedded Systems. actuate.

An Introduction to Parallel Programming

Synchronization in Concurrent Programming. Amit Gupta

Actor-Oriented Design: Concurrent Models as Programs

Introduction to Locks. Intrinsic Locks

The Problem With Threads

Imperative model of computation

Synchronization II: EventBarrier, Monitor, and a Semaphore. COMPSCI210 Recitation 4th Mar 2013 Vamsi Thummala

Multiple Inheritance. Computer object can be viewed as

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (II)

G Programming Languages Spring 2010 Lecture 13. Robert Grimm, New York University

CMSC 330: Organization of Programming Languages

Midterm Exam Amy Murphy 19 March 2003

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

Synchronization SPL/2010 SPL/20 1

Sharing Objects Ch. 3

Midterm Exam. CS169 Fall November 17, 2009 LOGIN: NAME: SID: Problem Max Points Points TOTAL 100

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2004

CMSC 433 Programming Language Technologies and Paradigms. Concurrency

Threads and Too Much Milk! CS439: Principles of Computer Systems February 6, 2019

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

Introduction to Embedded Systems

Interface Automata and Actif Actors

MODERN MULTITHREADING

Lecture 8: September 30

Balance between Formal and Informal Methods, Engineering and Artistry, Evolution and Rebuild

Threads and Parallelism in Java

Parallel Programming Multicore systems

Classes and Inheritance in Actor- Oriented Models

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

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

CS510 Advanced Topics in Concurrency. Jonathan Walpole

3/25/14. Lecture 25: Concurrency. + Today. n Reading. n P&C Section 6. n Objectives. n Concurrency

CS5460: Operating Systems

CS140 Operating Systems and Systems Programming Midterm Exam

Atomicity CS 2110 Fall 2017

Threads and Too Much Milk! CS439: Principles of Computer Systems January 31, 2018

THREADS AND CONCURRENCY

Embedded Tutorial CPS Foundations

Performance Throughput Utilization of system resources

Cover Page. The handle holds various files of this Leiden University dissertation

Thread-Local. Lecture 27: Concurrency 3. Dealing with the Rest. Immutable. Whenever possible, don t share resources

Concurrent Models of Computation

EE382V: Embedded System Design and Modeling

Introducing Embedded Systems: A Cyber- Physical Systems Approach

CS 31: Intro to Systems Threading & Parallel Applications. Kevin Webb Swarthmore College November 27, 2018

Concurrent ML. John Reppy January 21, University of Chicago

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions

THE UNIVERSITY OF WESTERN AUSTRALIA SAMPLE EXAM QUESTIONS 2007 WITH SOLUTIONS SCHOOL OF COMPUTER SCIENCE CITS3213 CONCURRENT PROGRAMMING (PART II)

Today: Synchronization. Recap: Synchronization

Runtime Atomicity Analysis of Multi-threaded Programs

MS Windows Concurrency Mechanisms Prepared By SUFIAN MUSSQAA AL-MAJMAIE

Concurrency: State Models & Design Patterns

RACE CONDITIONS AND SYNCHRONIZATION

CSCI-1200 Data Structures Fall 2009 Lecture 25 Concurrency & Asynchronous Computing

Concurrent Component Patterns, Models of Computation, and Types

Models of concurrency & synchronization algorithms

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5

Threads Synchronization

Synchronization Lecture 24 Fall 2018

Concurrent Programming

Concurrency & Parallelism. Threads, Concurrency, and Parallelism. Multicore Processors 11/7/17

Models of computation

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

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

C++ Memory Model. Don t believe everything you read (from shared memory)

Warm-up question (CS 261 review) What is the primary difference between processes and threads from a developer s perspective?

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Threads, Concurrency, and Parallelism

740: Computer Architecture Memory Consistency. Prof. Onur Mutlu Carnegie Mellon University

Internet and Intranet Protocols and Applications

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

Written Presentation: JoCaml, a Language for Concurrent Distributed and Mobile Programming

Introduction to Embedded Systems

CS370 Operating Systems Midterm Review

CSE 120 Principles of Operating Systems

CSE332: Data Abstractions Lecture 19: Mutual Exclusion and Locking

Problems with Concurrency. February 19, 2014

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

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

Concurrent Programming Method for Embedded Systems

Overview. Background: Efforts Prior to EduPar 11. EduPar 11 Outcome (I): Required Core Modules. EduPar 11 Outcome (II): Advanced/Elective Modules

Grand Central Dispatch

3/7/18. Secure Coding. CYSE 411/AIT681 Secure Software Engineering. Race Conditions. Concurrency

Multi-core Architectures. Dr. Yingwu Zhu

Transcription:

The Problem with Treads Edward A. Lee Programming Technology Lecture 2 11/09/08

Background on Edward A. Lee Bachelors degree (Yale University) (1979) Master degree (MIT) (1981) Ph.D. (U. C. Berkeley) (1986) Fellow of the IEEE Robert S. Pepper Distinguished Professor Former chair of the Electrical Engineering and Computer Sciences department at U.C. Berkeley Director of Berkeley Center for Hybrid and Embedded Software Systems Director of the Berkeley Ptolemy project He is co-author of five books and numerous papers.

About IEEE Computer The largest society in IEEE Founded i 1946 "Dedicated to advancing the theory and application of computer and information-processing technology" Known worldwide for its computer-standards activities The CS promotes an active exchange of ideas and technological innovation among its members

Intro Concurrent programming is difficult. Concurrent programming is becoming more urgent. The performance gains in computing, must be done by exploiting parallelism Automatic exploitation of parallelism in sequential programs Automatic program parallelization of sequential programs Automatic techniques have been pushed about as far as it will go It capable of exploiting only modest parallelism

Human vs. concurrency Physical world is highly concurrent survival depends on our ability to reason about concurrent physical dynamic Concurrent abstractions Not resemble the concurrency of the physical world Used to these computational abstractions That we think that the can not change The paper argue that the difficulty of concurrent programming is a consequence of the abstractions, the problem will be fixable if let go of those abstractions.

Threads The dominating approach to concurrent programming Sequential processes that share memory Key concurrency model supported by modern computers programming languages operating systems Symmetric multiprocessors are direct hardware realizations of the thread abstraction Can effectively be used by Webserver independence of these applications more like processes than threads where memory is not shared database abstractions However client-side applications are not so simple.

Threads Not the only possibility data parallel language extensions message passing libraries These are often used in scientific computing where threads not are the dominating solution This often differ significantly from so-called general purpose architectures In embedded applications reliability and predictability over expressiveness or performance The paper argues that achieving reliability and predictability using threads is essentially impossible for many applications.

Threads The core abstraction, which all widely-used programming languages are built on, emphasizes deterministic composition of deterministic components Threads are wildly nondeterministic The programmer has the job to prune away that nondeterminism by using Semaphores Monitors The Paper argue that we must (and can) build concurrent models of computation that are far more deterministic, and that we must judiciously and carefully introduce nondeterminism where needed.

public class ValueHolder { private List listeners = new LinkedList(); private int value; public interface Listener { public void valuechanged(int newvalue); public void addlistener(listener listener) { listeners.add(listener); public void setvalue(int newvalue) { value = newvalue; Iterator i = listeners.iterator(); while(i.hasnext()) { ((Listener)i.next()).valueChanged(newValue);

public class ValueHolder { private List listeners = new LinkedList(); private int value; public interface Listener { public void valuechanged(int newvalue); public void addlistener(listener listener) { listeners.add(listener); public void setvalue(int newvalue) { value = newvalue; Iterator i = listeners.iterator(); while(i.hasnext()) { ((Listener)i.next()).valueChanged(newValue);

public class ValueHolder { private List listeners = new LinkedList(); private int value; public interface Listener { public void valuechanged(int newvalue); public void addlistener(listener listener) { listeners.add(listener); public void setvalue(int newvalue) { value = newvalue; Iterator i = listeners.iterator(); while(i.hasnext()) { ((Listener)i.next()).valueChanged(newValue);

public class ValueHolder { private List listeners = new LinkedList(); private int value; public interface Listener { public void valuechanged(int newvalue); public synchronized void addlistener(listener listener) { listeners.add(listener); public void setvalue(int newvalue) { List copyoflisteners; synchronized(this) { value = newvalue; copyoflisteners = new LinkedList(listeners); Iterator i = copyoflisteners.iterator(); while(i.hasnext()) { ((Listener)i.next()).valueChanged(newValue);

public class ValueHolder { private List listeners = new LinkedList(); private int value; public interface Listener { public void valuechanged(int newvalue); public synchronized void addlistener(listener listener) { listeners.add(listener); public void setvalue(int newvalue) { List copyoflisteners; synchronized(this) { value = newvalue; copyoflisteners = new LinkedList(listeners); Iterator i = copyoflisteners.iterator(); while(i.hasnext()) { ((Listener)i.next()).valueChanged(newValue);

public class ValueHolder { private List listeners = new LinkedList(); private int value; public interface Listener { public void valuechanged(int newvalue); public synchronized void addlistener(listener listener) { listeners.add(listener); public void setvalue(int newvalue) { List copyoflisteners; synchronized(this) { value = newvalue; copyoflisteners = new LinkedList(listeners); Iterator i = copyoflisteners.iterator(); while(i.hasnext()) { ((Listener)i.next()).valueChanged(newValue);

public class ValueHolder { private List listeners = new LinkedList(); private int value; public interface Listener { public void valuechanged(int newvalue); public synchronized void addlistener(listener listener) { listeners.add(listener); public void setvalue(int newvalue) { List copyoflisteners; synchronized(this) { value = newvalue; copyoflisteners = new LinkedList(listeners); Iterator i = copyoflisteners.iterator(); while(i.hasnext()) { ((Listener)i.next()).valueChanged(newValue);

public class ValueHolder { private List listeners = new LinkedList(); private int value; public interface Listener { public void valuechanged(int newvalue); public synchronized void addlistener(listener listener) { listeners.add(listener); public void setvalue(int newvalue) { List copyoflisteners; synchronized(this) { value = newvalue; copyoflisteners = new LinkedList(listeners); Iterator i = copyoflisteners.iterator(); while(i.hasnext()) { ((Listener)i.next()).valueChanged(newValue);

Fixing Threads by More Aggressive Pruning Better software engineering processes Ptolemy Project (2000) code maturity rating system design reviews code reviews nightly builds regression tests 100 percent code coverage No problems were observed until the code deadlocked four years later The paper conclude that testing may never reveal all the problems in nontrivial multithreaded code. Quick fix: always acquire locks in the same order method signature do not indicates what locks, it needs

Fixing Threads by More Aggressive Pruning 2 Software engineering process improvements alone will not do the job Use transactions, like in databases well-suited for multiple actors compete nondeterministically for resources not well-suited for building determinate concurrent interactions Concurrency is encapsulated into libraries by experts Using Proxies of the data Introduces formal program analysis to identify potential concurrency bugs in multi threaded programs still require considerable expertise Fix some but not all still result in highly nondeterministic programs

Fixing Threads by More Aggressive Pruning 2 Instead of startingwith a highly nondeterministic mechanism like threads, and relying on the programmer to prune that nondeterminacy, we should start with deterministic, and introduce nondeterminism only where needed

Alternatives to Threads

Alternatives to Threads 2

Alternatives to Threads 3 everything about the program is deterministic except the explicitly nondeterministic interaction specified by the Merge block

Challenges and Opportunities alternatives to threads have been around for a long time the core abstractions of computation, are deeply rooted in the sequential paradigm threads are either a minor extension to these languages java, just an external library. We should not replace established languages. We should instead build on them. The paper believe that the right answer is coordination languages. But coordination languages have also been around for a long time failed because of the homogeneity

Conclusion Concurrency in software is difficult blame ourselves of the abstractions for concurrency that we have chosen The dominant one is Threads We can improve by using design patterns better granularity of atomicity (e.g. transactions) improved languages formal methods Concurrent programming models can be constructed that are much more predictable and understandable than threads Nondeterminism should be introduced where needed, and should be explicit in programs

My Conclusion Threads are generally not bad Too much work in not using them Know what, you are doing, when programming

Reviewer Questions