Topics. Producing Production Quality Software. Concurrent Environments. Why Use Concurrency? Models of concurrency Concurrency in Java



Similar documents
Last Class: Semaphores

CS11 Java. Fall Lecture 7

The Therac 25 A case study in safety failure. Therac 25 Background

Mutual Exclusion using Monitors

Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification

Chapter 6, The Operating System Machine Level

Chapter 6 Concurrent Programming

Outline of this lecture G52CON: Concepts of Concurrency

Monitors, Java, Threads and Processes

Java Virtual Machine Locks

Real Time Programming: Concepts

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Control 2004, University of Bath, UK, September 2004

3C03 Concurrency: Condition Synchronisation

Multi-core Programming System Overview

Java Memory Model: Content

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Semaphores and Monitors: High-level Synchronization Constructs

Operating Systems for Parallel Processing Assistent Lecturer Alecu Felician Economic Informatics Department Academy of Economic Studies Bucharest

Replication on Virtual Machines

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

Course Development of Programming for General-Purpose Multicore Processors

Monitors and Semaphores

Comparison of Concurrency Frameworks for the Java Virtual Machine

! Past few lectures: Ø Locks: provide mutual exclusion Ø Condition variables: provide conditional synchronization

Monitor Object. An Object Behavioral Pattern for Concurrent Programming. Douglas C. Schmidt

Programming real-time systems with C/C++ and POSIX

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis

Computer Science 483/580 Concurrent Programming Midterm Exam February 23, 2009

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Effective Computing with SMP Linux

Centralized Systems. A Centralized Computer System. Chapter 18: Database System Architectures

Operating Systems 4 th Class

Gildart Haase School of Computer Sciences and Engineering

A Survey of Parallel Processing in Linux

Linux Process Scheduling Policy

CS Fall 2008 Homework 2 Solution Due September 23, 11:59PM

Why Threads Are A Bad Idea (for most purposes)

Chapter 2: OS Overview

Chapter 18: Database System Architectures. Centralized Systems

Chapter 12: Multiprocessor Architectures. Lesson 01: Performance characteristics of Multiprocessor Architectures and Speedup

CS550. Distributed Operating Systems (Advanced Operating Systems) Instructor: Xian-He Sun

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2007 Lecture 5 - DBMS Architecture

Comp 204: Computer Systems and Their Implementation. Lecture 12: Scheduling Algorithms cont d

Shared Address Space Computing: Programming

Performance Tools for Parallel Java Environments

Distributed Systems [Fall 2012]

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Embedded Parallel Computing

OPERATING SYSTEMS PROCESS SYNCHRONIZATION

Multithreaded Programming

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

First-class User Level Threads

Squashing the Bugs: Tools for Building Better Software

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Safety and Hazard Analysis

TESTING JAVA MONITORS BY STATE SPACE EXPLORATION MONICA HERNANDEZ. Presented to the Faculty of the Graduate School of

Lecture 6: Semaphores and Monitors

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Computer Systems Engineering: Spring Quiz I Solutions

SYSTEM ecos Embedded Configurable Operating System

Virtual machine interface. Operating system. Physical machine interface

Effective Java Programming. measurement as the basis

Transaction Performance Maximizer InterMax

Introduction of Virtualization Technology to Multi-Process Model Checking

PERFORMANCE TESTING CONCURRENT ACCESS ISSUE AND POSSIBLE SOLUTIONS A CLASSIC CASE OF PRODUCER-CONSUMER

Comparing Four Static Analysis Tools for Java Concurrency Bugs

Lecture 7: Java RMI. CS178: Programming Parallel and Distributed Systems. February 14, 2001 Steven P. Reiss

Road Map. Scheduling. Types of Scheduling. Scheduling. CPU Scheduling. Job Scheduling. Dickinson College Computer Science 354 Spring 2010.

Thread Synchronization and the Java Monitor

CS414 SP 2007 Assignment 1

Overview. CMSC 330: Organization of Programming Languages. Synchronization Example (Java 1.5) Lock Interface (Java 1.5) ReentrantLock Class (Java 1.

INTERNATIONAL JOURNAL OF COMPUTER ENGINEERING & TECHNOLOGY (IJCET)

Hoare-Style Monitors for Java

COURSE OUTLINE Survey of Operating Systems

OPERATING SYSTEMS STRUCTURES

Deciding which process to run. (Deciding which thread to run) Deciding how long the chosen process can run

JAVA - MULTITHREADING

Scheduler Activations: Effective Kernel Support for the User-Level Management of Parallelism

Operating System Support for Java Virtual Machine: A New Methodology of Boosting Java Runtime Performance

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

OPERATING SYSTEMS Internais and Design Principles

Understanding Hardware Transactional Memory

Operatin g Systems: Internals and Design Principle s. Chapter 10 Multiprocessor and Real-Time Scheduling Seventh Edition By William Stallings

Concurrent programming in Java

CPU Scheduling. CSC 256/456 - Operating Systems Fall TA: Mohammad Hedayati

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

Division of Informatics, University of Edinburgh

Weighted Total Mark. Weighted Exam Mark

Java Mission Control

A Thread Monitoring System for Multithreaded Java Programs

An Implementation Of Multiprocessor Linux

Transcription:

Topics Producing Production Quality Software Models of concurrency Concurrency in Java Lecture 12: Concurrent and Distributed Programming Prof. Arthur P. Goldberg Fall, 2005 2 Why Use Concurrency? Concurrent Environments Enable programs that interact with a (naturally concurrent) environment E.g., GUI programming, OS interaction Support organization into parts that execute independently and interact as needed E.g., client/server and producer/consumer programs Enable speedup by parallel execution Number of processors One Many Number of machines (memories) One Standard uniprocessor Shared memory multiprocessor Many Many shared memory multiprocessors 3 4

Concurrency Models Dataflow Execution Dataflow Multiple concurrent sequential programs Many others 5 Execute all computations that are ready Do not use a variable before it is bound A statement using the variable suspends until another thread binds the variable Avoids complexities associated with other forms of concurrency But overhead of naïve implementation is typically too large for practical use Well described by Roy and Haridi 6 Multiple concurrent programs Processes with message passing Communicating Sequential Processes (CSP) Hoare Threads with shared memory 7 Nondeterminism of Concurrent Computations Results may depend on order in which shared data accessed Observable nondeterminism: race condition Programs with state and concurrency are difficult to reason about and make correct E.g., Therac-25 radiation therapy machines Overdoses by factors of 1000 Killed a handful of people Difficult to test Heisenbug But see ConTest 8

Therac-25 Cancer treatment machine that emitted photons and electrons Accidental overdoses killed 2 and injured 4 Software allowed concurrent access to shared memory No synchronization Test and set not indivisible Some injuries caused by interaction between treatment code and input See pp. 22 28 of Leveson See http://courses.cs.vt.edu/~cs3604/lib/therac_25/figure.2.gif Techniques for Controlling Nondeterminism Atomicity Locking Message passing Many others 9 10 Other Undesirable Behavior Concurrency in Java Deadlock Starvation Threads within a JVM RMI 11 12

java.lang.thread Review JVM runs multiple threads concurrently Higher priority threads execute preferentially JVM terminates when Runtime.exit is called All threads that are not daemon threads die 13 join(long millis) Thread Scheduling start() This thread begins execution; the JVM calls the thread s run() method yield() The currently executing thread temporarily pauses to allow other threads to execute. sleep(long millis) The currently executing thread temporarily ceases execution for the specified number of milliseconds. interrupt() Interrupts this thread. Waits at most millis milliseconds for this thread to die. 14 Deprecated Thread Scheduling Methods All these methods were a bad idea! resume() stop() suspend() Those Java guys really screwed up Thread Monitor Actions Each object maintains 1 lock, or monitor wait(long timeout) void notify() void notifyall( ) Causes current thread to wait until either another thread invokes the notify() method or the notifyall() method for this object, or a specified amount of time has elapsed. The current thread must own this object's monitor. Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object's monitor by calling one of the wait methods. Wake up all threads that are waiting on this object s monitor. 15

JVM Threads Model Java Memory Model Synchronizing threads Monitor At most one thread at a time can execute a protected region of code Monitors are implemented with locks One lock per object synchronized statement Identify the object Acquire (lock) the object s lock Execute the synchronized code Release (unlock) the object s lock 17 Totally ordered actions Actions by a thread Actions by main memory on any one variable Actions by main memory on any lock 18 References The End Roy and Haridi, Concepts, Techniques, and Models of Computer Programming, March 2004, ISBN 0-262-22069-5, The MIT Press (The Oz language and the Mozart Programming System) Nancy Leveson, Clark S. Turner, An Investigation of the Therac- 25 Accidents, IEEE Computer, Vol. 26, No. 7, July 1993, pp. 18-41. http://sunnyday.mit.edu/papers/therac.pdf CHAPTER 17, Threads and Locks, of the Java Language Specification, http://java.sun.com/docs/books/jls/second_edition/html/memory.d Tony Hoare, "Communicating Sequential Processes", 1985 ConTest - A Tool for Testing Multi-threaded Java Applications, http://www.haifa.il.ibm.com/projects/verification/contest/ 19 20