Concurrent programming for dummies (and smart people too) Tim Harris & Keir Fraser.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
Hongjin Liang and Xinyu Feng
– R 7 :: 1 – 0024 Spring 2010 Parallel Programming 0024 Recitation Week 7 Spring Semester 2010.
50.003: Elements of Software Construction Week 6 Thread Safety and Synchronization.
Practice Session 7 Synchronization Liveness Deadlock Starvation Livelock Guarded Methods Model Thread Timing Busy Wait Sleep and Check Wait and Notify.
Software Transactional Memory and Conditional Critical Regions Word-Based Systems.
Ch 7 B.
ECE 454 Computer Systems Programming Parallel Architectures and Performance Implications (II) Ding Yuan ECE Dept., University of Toronto
Chapter 6: Process Synchronization
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
Mutual Exclusion.
1 Mutual Exclusion: Primitives and Implementation Considerations.
Concurrency (3) CSE 132. iClicker/WUTexter Question The following four numbers are in 8-bit 2’s complement form: Which.
COS 461 Fall 1997 Concurrent Programming u Traditional programs do one thing at a time. u Concurrent programs do several things at once. u Why do this?
Exceptions and side-effects in atomic blocks Tim Harris.
Language Support for Lightweight transactions Tim Harris & Keir Fraser Presented by Narayanan Sundaram 04/28/2008.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 19 th, 2010 The University of Georgia.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
CS510 Concurrent Systems Introduction to Concurrency.
Today’s Agenda  Quick Review  Finish Java Threads  The CS Problem Advanced Topics in Software Engineering 1.
A Qualitative Survey of Modern Software Transactional Memory Systems Virendra J. Marathe Michael L. Scott.
CS5204 – Operating Systems Transactional Memory Part 2: Software-Based Approaches.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Internet Software Development Controlling Threads Paul J Krause.
Synchronized and Monitors. synchronized is a Java keyword to denote a block of code which must be executed atomically (uninterrupted). It can be applied.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Java Thread and Memory Model
Dr. R R DOCSIT, Dr BAMU. Basic Java :Multi Threading Cont. 2 Objectives of This Session Explain Synchronization in threads Demonstrate use of.
The ATOMOS Transactional Programming Language Mehdi Amirijoo Linköpings universitet.
SPL/2010 Guarded Methods and Waiting 1. SPL/2010 Reminder! ● Concurrency problem: asynchronous modifications to object states lead to failure of thread.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
Software Transactional Memory Should Not Be Obstruction-Free Robert Ennals Presented by Abdulai Sei.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Thread A thread represents an independent module of an application that can be concurrently execution With other modules of the application. MULTITHREADING.
AtomCaml: First-class Atomicity via Rollback Michael F. Ringenburg and Dan Grossman University of Washington International Conference on Functional Programming.
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
Implementing Lock. From the Previous Lecture  The “too much milk” example shows that writing concurrent programs directly with load and store instructions.
CS510 Concurrent Systems Jonathan Walpole. Introduction to Concurrency.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
R 1 Transactional abstractions: beyond atomic update Tim Harris r.
Tutorial 2: Homework 1 and Project 1
CS703 – Advanced Operating Systems
Part 2: Software-Based Approaches
Atomicity CS 2110 – Fall 2017.
Semaphore Originally called P() and V() wait (S) { while S <= 0
Multithreading.
Critical section problem
Chapter 6: Process Synchronization
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
CS333 Intro to Operating Systems
Don Porter Portions courtesy Emmett Witchel
Synchronization and liveness
Presentation transcript:

Concurrent programming for dummies (and smart people too) Tim Harris & Keir Fraser

Example: hashtable Hashtable object Array of buckets Chains of key,value pairs  Where should the locking be done?

{ int result; if (!this.full) wait(); result = this.val; this.full = false; notify(); return result; } { if (this.full) wait(); this.full = true; this.val = val; notify(); } Example: single-cell buffer void put(int val)int get()  Methods should be marked as synchronized  ‘ wait() ’ can wake up spuriously so must be in a loop  ‘ notifyAll() ’ should be used in place of ‘ notify() ’ for liveness

Conditional critical regions in Java void put(int val) { atomic (!this.full) { this.full = true; this.val = val; } int get() { int result; atomic (this.full) { this.full = false; return this.val; }  Basic syntax: ‘ atomic (cond) { statements; } ’  Execute the statements exactly once…  …starting in a state where the condition is true  The statements can access fields & local variables, invoke methods, instantiate objects etc.

Implementation overview Source code Bytecode + extended attributes Software transactional memory operations Machine code instructions

Implementation overview (ii)  Native STM interface:  Transaction management  void STMStartTransaction(void)  boolean STMCommitTransaction(void)  void STMAbortTransaction(void)  Blocking  void STMWait(void)  Data access  word_t STMReadValue(addr_t a)  void STMWriteValue(addr_t a, word_t w) Exposed as static methods Called from interpreter / JIT’d code

Data storage a5: a1: Ownership records (orecs) version 42 version 17 Proposed updates Status: ACTIVE a1: (100,42) -> (777,43) a5: (200,17) -> (888,18) Heap structure

 Acquire exclusive access to each ownership record needed  Check that they hold the correct versions  Set status to committed/aborted  Make updates to the heap (if needed)  Release ownership records, updating the versions a5: a1:version 42 version 17 Status: ACTIVE a1: (100,42) -> (777,43) a5: (200,17) -> (888,18) t1: CAS: 42 → t1 CAS: 17 → t1 CAS: active → committed Status: COMMITTED CAS: t1 → 43 CAS: t1 → 18 version 43 version 18 Non-contended updates

 Simple option:  Spin waiting for the owner to make its updates and release  Obstruction-free option:  Make updates on owner’s behalf and then releases ownership  Intricate: first thread may make updates at a later stage. Introduces ‘active updaters’ count into each orec – details in the paper  Hacky option:  Suspend the current owning thread  Make their updates  Revoke their ownership  Change their PC to be outside the commit operation  Resume the thread Contended updates

Compound swaps atomic {…} util.concurrent java.util #CPUs (1 thread per CPU) μs per operation

Compound swaps (ii) #CPUs (1 thread per CPU) μs per operation atomic {…} util.concurrent java.util

Memory management a5: a1:  Two problems: management of transaction descriptors & management of shared data structures reachable from them  So-called ‘A-B-A’ problems occur in most CAS-based systems  We’ve looked at a number of schemes:  Safe memory re-use (Michael)  Repeat offender problem (Herlihy et al)  Reference counting  Epoch-based schemes  In many cases we’re really allocating fresh pointers rather than needing ‘more’ memory

Memory management (II) a5: a1:  Our more recent STM introduces a Hold/Release abstraction:  A Hold operation acquires a revocable lock on a specified location  A Release operation relinquishes such a lock  A lock is revoked by a competing hold or by another thread writing to a held location  Revocation is exposed by displacing the previous owner to a specified PC  This lets us ensure only one thread at a time is working on a given transaction descriptor – MM much simplified  Software implementation using mprotect or /proc

 Evaluation beyond synthetic benchmarks  Try the C STM interface yourself: download under a BSD- style license from  Reflective exposure of a transactional API  Create, enter, leave transactions  Possibly enables better I/O handling  Opportunities for new hardware instructions Future directions