Understandable Concurrency Edward A. Lee Professor, Chair of EE, and Associate Chair of EECS Director, CHESS: Center for Hybrid and Embedded Software Systems.

Slides:



Advertisements
Similar presentations
Technische universität dortmund fakultät für informatik informatik 12 Models of computation Peter Marwedel TU Dortmund Informatik 12 Graphics: © Alexandra.
Advertisements

Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Concurrency The need for speed. Why concurrency? Moore’s law: 1. The number of components on a chip doubles about every 18 months 2. The speed of computation.
1 Concurrency Specification. 2 Outline 4 Issues in concurrent systems 4 Programming language support for concurrency 4 Concurrency analysis - A specification.
Topic 2: Balance between formal and informal methods, engineering and artistry, evolution and rebuild Edward A. Lee Professor UC Berkeley Center for Hybrid.
Concurrent Computational Systems Edward A. Lee Professor, UC Berkeley Ptolemy Project CHESS: Center for Hybrid and Embedded Software Systems University.
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
Based on work by Edward A. Lee (2006) Presented by Leeor Peled, June 2010 Seminar in VLSI Architectures (048879)
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
PTIDES: Programming Temporally Integrated Distributed Embedded Systems Yang Zhao, EECS, UC Berkeley Edward A. Lee, EECS, UC Berkeley Jie Liu, Microsoft.
Chess Review May 8, 2003 Berkeley, CA Classes and Inheritance in Actor- Oriented Models Stephen Neuendorffer Edward Lee UC Berkeley.
7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Leveraging Synchronous Language Principles for Hybrid System Models Haiyang Zheng and.
Behavioral Types as Interface Definitions for Concurrent Components Center for Hybrid and Embedded Software Systems Edward A. Lee Professor UC Berkeley.
Understandable and Scalable Concurrency Christopher Brooks Programmer/Analyst, University of California, Berkeley Edward A. Lee Robert S. Pepper Distinguished.
February 11, 2010 Center for Hybrid and Embedded Software Systems Ptolemy II - Heterogeneous Concurrent Modeling and Design.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Chess Review October 4, 2006 Alexandria, VA Edited and presented by Advanced Tool Architectures Edward A. Lee UC Berkeley.
Disciplined Concurrent Models of Computation for Parallel Software Edward A. Lee Robert S. Pepper Distinguished Professor and UC Berkeley Invited Keynote.
Concurrency CS 510: Programming Languages David Walker.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Server Architecture Models Operating Systems Hebrew University Spring 2004.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Building Unreliable Systems out of Reliable Components: The Real Time Story Edward A. Lee Professor, Chair of EE, and Associate Chair of EECS CHESS: Center.
Chess Review November 21, 2005 Berkeley, CA Edited and presented by Causality Interfaces and Compositional Causality Analysis Rachel Zhou UC Berkeley.
Semaphores CSCI 444/544 Operating Systems Fall 2008.
NSF Foundations of Hybrid and Embedded Software Systems UC Berkeley: Chess Vanderbilt University: ISIS University of Memphis: MSI A New System Science.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
SEC PI Meeting Annapolis, May 8-9, 2001 Component-Based Design of Embedded Control Systems Edward A. Lee & Jie Liu UC Berkeley with thanks to the entire.
Department of Electrical Engineering and Computer Sciences University of California at Berkeley Concurrent Component Patterns, Models of Computation, and.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 PTIDES: A Programming Model for Time- Synchronized Distributed Real-time Systems Yang.
UC Berkeley CS169, November 1, 2007 Software Development in an Academic Environment: Lessons learned and not learned Christopher Brooks CHESS Executive.
7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 Ptolemy Project Vision Edward A. Lee Robert S. Pepper Distinguished Professor and Chair.
Embedded Software: Leveraging Concurrent Models of Computation Edward A. Lee Professor, UC Berkeley Center for Hybrid and Embedded Software Systems (CHESS)
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Panel: What Comes After C++ in System-Level Specification Edward Lee UC Berkeley Forum on Design Languages Workshop on System Specification & Design Languages.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Department of Electrical Engineering and Computer Sciences University of California at Berkeley The Ptolemy II Framework for Visual Languages Xiaojun Liu.
Embedded Software: Building the Foundations Edward A. Lee Professor, Chair of EE, and Associate Chair of EECS CHESS: Center for Hybrid and Embedded Software.
Monitor  Giving credit where it is due:  The lecture notes are borrowed from Dr. I-Ling Yen at University of Texas at Dallas  I have modified them and.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
Games Development 2 Concurrent Programming CO3301 Week 9.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
Internet Software Development Controlling Threads Paul J Krause.
The 14 th IEEE Real-Time and Embedded Technology and Applications Symposium, April 2008 Real-Time Distributed Discrete-Event Execution with Fault Tolerance.
Design Languages in 2010 Chess: Center for Hybrid and Embedded Software Systems Edward A. Lee Professor UC Berkeley Panel Position Statement Forum on Design.
Threads Doing Several Things at Once. Threads n What are Threads? n Two Ways to Obtain a New Thread n The Lifecycle of a Thread n Four Kinds of Thread.
Actor Networks Edward A. Lee Robert S. Pepper Distinguished Professor Chair of EECS UC Berkeley Invited Talk Workshop Foundations and Applications of Component-based.
Incremental Checkpointing with Application to Distributed Discrete Event Simulation Thomas Huining Feng and Edward A. Lee {tfeng,
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Making Concurrency Mainstream Edward A. Lee Professor, Chair of EECS UC Berkeley Joint Invited Talk CONCUR: Concurrency Theory & FMICS: Formal Methods.
C H A P T E R E L E V E N Concurrent Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Comunication&Synchronization threads 1 Programación Concurrente Benemérita Universidad Autónoma de Puebla Facultad de Ciencias de la Computación Comunicación.
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
The Future of Embedded Software Edward A. Lee Professor, Chair of EE, and Associate Chair of EECS UC Berkeley ARTEMIS 2006 Annual Conference Graz, Austria.
Ptolemy II - Heterogeneous Concurrent Modeling and Design in Java
Concurrency Demands New Foundations for Computing
Multithreading Tutorial
Ptolemy II - Heterogeneous Concurrent Modeling and Design in Java
Concurrent Models of Computation
The Active Object Pattern
Multithreading Tutorial
Ptolemy II - Heterogeneous Concurrent Modeling and Design in Java
Multithreading Tutorial
Monitor Giving credit where it is due:
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 19
Presentation transcript:

Understandable Concurrency Edward A. Lee Professor, Chair of EE, and Associate Chair of EECS Director, CHESS: Center for Hybrid and Embedded Software Systems Director, Ptolemy Project UC Berkeley Chess Review November 21, 2005 Berkeley, CA

Lee, Chess Review 2Understandable Concurrency What would it take to make reliable concurrent software? The standard concurrency model, based on: threads, semaphores, and mutual exclusion locks results in programs that are incomprehensible to humans. These methods date to the 1960’s [Dijkstra]. Tauntingly simple rules (e.g. always grab locks in the same order [Lea]) are impossible to apply in practice. Formal methods can expose flaws, but cannot make programs understandable.

Lee, Chess Review 3Understandable Concurrency Red Herrings Training programmers to use threads. Software engineering process improvements. Attention to “non-functional” properties. Design patterns. Quality of service. None of these deliver a rigorous, analyzable, and understandable model of concurrency.

Lee, Chess Review 4Understandable Concurrency Problems with Threads: Example: Simple Observer Pattern public void addListener(listener) {…} public void setValue(newValue) { myValue = newValue; for (int i = 0; i < myListeners.length; i++) { myListeners[i].valueChanged(newValue) } Thanks to Mark S. Miller, HP Labs, for the details of this example. What’s wrong with this (in a multithreaded context)?

Lee, Chess Review 5Understandable Concurrency Example: Simple Observer Pattern With Mutual Exclusion (Mutexes) using Monitors public synchronized void addListener(listener) {…} public synchronized void setValue(newValue) { myValue = newValue; for (int i = 0; i < myListeners.length; i++) { myListeners[i].valueChanged(newValue) } Javasoft recommends against this. What’s wrong with it?

Lee, Chess Review 6Understandable Concurrency Mutexes using Monitors are Minefields public synchronized void addListener(listener) {…} public synchronized void setValue(newValue) { myValue = newValue; for (int i = 0; i < myListeners.length; i++) { myListeners[i].valueChanged(newValue) } valueChanged() may attempt to acquire a lock on some other object and stall. If the holder of that lock calls addListener(), deadlock!

Lee, Chess Review 7Understandable Concurrency We made exactly this mistake when a code review identified exactly this concurrency flaw in Ptolemy II.

Lee, Chess Review 8Understandable Concurrency Simple Observer Pattern Becomes Not So Simple public synchronized void addListener(listener) {…} public void setValue(newValue) { synchronized(this) { myValue = newValue; listeners = myListeners.clone(); } for (int i = 0; i < listeners.length; i++) { listeners[i].valueChanged(newValue) } while holding lock, make copy of listeners to avoid race conditions notify each listener outside of synchronized block to avoid deadlock This still isn’t perfect. What’s wrong with it?

Lee, Chess Review 9Understandable Concurrency Simple Observer Pattern: Is it Even Possible to Make It Right? public synchronized void addListener(listener) {…} public void setValue(newValue) { synchronized(this) { this.myValue = newValue; listeners = myListeners.clone(); } for (int i = 0; i < listeners.length; i++) { listeners[i].valueChanged(newValue) } Suppose two threads call setValue(). One of them will set the value last, leaving that value in the object, but listeners may be notified in the opposite order. The listeners may be alerted to the value changes in the wrong order!

Lee, Chess Review 10Understandable Concurrency This is Ridiculous… One of the simplest, textbook design patterns, commonly used throughout concurrent programs, becomes a potential Masters Thesis!

Lee, Chess Review 11Understandable Concurrency … and it Still Gets Worse… /** CrossRefList is a list that maintains pointers to other CrossRefLists. Geroncio Galicia, Contributor: Edward A. $Id: CrossRefList.java,v /04/29 14:50:00 eal Exp Ptolemy II Green Green (bart) */ public final class CrossRefList implements Serializable { … protected class CrossRef implements Serializable{ … // NOTE: It is essential that this method not be // synchronized, since it is called by _farContainer(), // which is. Having it synchronized can lead to // deadlock. Fortunately, it is an atomic action, // so it need not be synchronized. private Object _nearContainer() { return _container; } private synchronized Object _farContainer() { if (_far != null) return _far._nearContainer(); else return null; } … } Code that had been in use for four years, central to Ptolemy II, with an extensive test suite (100% code coverage), design reviewed to yellow, then code reviewed to green in 2000, causes a deadlock during a demo on April 26, 2004.

Lee, Chess Review 12Understandable Concurrency … and Doubts Remain /** CrossRefList is a list that maintains pointers to other CrossRefLists. Geroncio Galicia, Contributor: Edward A. $Id: CrossRefList.java,v /04/29 14:50:00 eal Exp Ptolemy II Green Green (bart) */ public final class CrossRefList implements Serializable { … protected class CrossRef implements Serializable{ … private synchronized void _dissociate() { _unlink(); // Remove this. // NOTE: Deadlock risk here! If _far is waiting // on a lock to this CrossRef, then we will get // deadlock. However, this will only happen if // we have two threads simultaneously modifying a // model. At the moment (4/29/04), we have no // mechanism for doing that without first // acquiring write permission the workspace(). // Two threads cannot simultaneously hold that // write access. if (_far != null) _far._unlink(); // Remove far } Safety of this code depends on policies maintained by entirely unconnected classes. The language and synchronization mechanisms provide no way to talk about these systemwide properties.

Lee, Chess Review 13Understandable Concurrency Nontrivial software written with threads, semaphores, and mutexes cannot and should not be trusted!

Lee, Chess Review 14Understandable Concurrency Stronger Synchronization Properties are Delivered by the Rendezvous MoC Conditional rendezvous marries one of the input processes with the output process. Model of computation: Processes communicating via rendezvous. Observer sees values at the same time as the Value Consumer Multiway rendezvous requires both consumer processes to be ready to consume. This is a generalization of CSP with multiway and conditional rendezvous, again implemented in a coordination language with a visual syntax. Deadlock is provably avoided

Lee, Chess Review 15Understandable Concurrency Observer Pattern in Process Networks is Trivial, as it Should Be! Explicit nondeterminism (vs. unexpressed race condition) Model of computation: Processes communicating via unbounded FIFO queues. Observer sees values in the same order as the Value Consumer You can think of this as a generalization of Unix Pipes implemented in a Coordination Language with a Visual Syntax. Deadlock is provably avoided

Lee, Chess Review 16Understandable Concurrency The Lee Principle of Nondeterminism Deterministic behavior should be accomplished with deterministic mechanisms. Only nondeterministic behavior should use nondeterministic mechanisms. This rules out using threads for almost any deterministic behavior!

Lee, Chess Review 17Understandable Concurrency Actor-Oriented Approached Don’t Guarantee Good Design The two models at the right implement the same function, but the upper one uses subtle and complex nondeterministic mechanisms, while the one at the bottom uses simple and direct deterministic mechanisms.

Lee, Chess Review 18Understandable Concurrency Make Easy Concurrency Properties Easy, so We Can Focus on the Harder Ones Timing Controlled nondeterminacy Consistency in distributed programs Simultaneity Fairness …

Lee, Chess Review 19Understandable Concurrency Example: Coordinating Timing of Independent Processes

Lee, Chess Review 20Understandable Concurrency These Techniques are Examples of a Family of Concurrent Component Technologies The new: Actor oriented: actor name data (state) ports Input data parameters Output data What flows through an object is streams of data class name data methods call return What flows through an object is sequential control The old: Object-oriented: Things happen to objects Actors make things happen

Lee, Chess Review 21Understandable Concurrency Useful Actor-Oriented Models of Computation Synchronous/reactive (SCADE, Esterel, Statecharts, …) Time triggered (Giotto, Simulink, …) Dataflow (Labview, SPW, …) Discrete events (VHDL, Verilog, Opnet, Visualsense, …) Distributed discrete-events (Croquet, Time Warp, …) Continuous time (Simulink, …) Hybrid systems (HyVisual, Charon, …) Event triggered (xGiotto, nesC/TinyOS, …) … None of these have threads!

Lee, Chess Review 22Understandable Concurrency Conclusion The time is right to create a 21-st century technology for concurrent computing.