Software Transactional Memory Steve Severance – Alpha Heavy Industries.

Slides:



Advertisements
Similar presentations
Copyright 2008 Sun Microsystems, Inc Better Expressiveness for HTM using Split Hardware Transactions Yossi Lev Brown University & Sun Microsystems Laboratories.
Advertisements

Monads & Gonads Douglas Crockford.
Concurrency unlocked transactional memory for composable concurrency Tim Harris Maurice Herlihy Simon Marlow Simon Peyton Jones.
Kathleen Fisher cs242 Reading: “Beautiful Concurrency”,Beautiful Concurrency “The Transactional Memory / Garbage Collection Analogy”The Transactional Memory.
Lecture 5 Concurrency and Process/Thread Synchronization     Mutual Exclusion         Dekker's Algorithm         Lamport's Bakery Algorithm.
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.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Rich Transactions on Reasonable Hardware J. Eliot B. Moss Univ. of Massachusetts,
Parallel and Concurrent Haskell Part II Simon Marlow (Microsoft Research, Cambridge, UK)
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
Simon Peyton Jones (Microsoft Research) Tokyo Haskell Users Group April 2010.
We should define semantics for languages, not for TM Tim Harris (MSR Cambridge)
Parallelism and Concurrency Koen Lindström Claessen Chalmers University Gothenburg, Sweden Ulf Norell.
Language Support for Concurrency. 2 Common programming errors Process i P(S) CS P(S) Process j V(S) CS V(S) Process k P(S) CS.
Exceptions and side-effects in atomic blocks Tim Harris.
Concurrency, Threads, and Events Robbert van Renesse.
Department of Computer Science Presenters Dennis Gove Matthew Marzilli The ATOMO ∑ Transactional Programming Language.
1 Thread Pools. 2 What’s A Thread Pool? A programming technique which we will use. A collection of threads that are created once (e.g. when server starts).
Parallelism COS 597C David August David Walker. Goals To compare and contrast a variety of different programming languages and programming styles –imperative.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Transactions and Reliability. File system components Disk management Naming Reliability  What are the reliability issues in file systems? Security.
 George Chrysanthakopoulos Software Architect Microsoft Corporation.
Lightweight Concurrency in GHC KC Sivaramakrishnan Tim Harris Simon Marlow Simon Peyton Jones 1.
David Walker Optional Reading: “Beautiful Concurrency”, “The Transactional Memory / Garbage Collection Analogy” “A Tutorial on Parallel and Concurrent.
 Actor Model  Software Transactional Memory  Data Flow Programming.
Microsoft Research Faculty Summit Panacea or Pandora’s Box? Software Transactional Memory Panacea or Pandora’s Box? Christos Kozyrakis Assistant.
Kathleen Fisher cs242 Reading: “Beautiful Concurrency”,Beautiful Concurrency “The Transactional Memory / Garbage Collection Analogy”The Transactional Memory.
Threading and Concurrency Issues ● Creating Threads ● In Java ● Subclassing Thread ● Implementing Runnable ● Synchronization ● Immutable ● Synchronized.
CSE 230 Concurrency: STM Slides due to: Kathleen Fisher, Simon Peyton Jones, Satnam Singh, Don Stewart.
Meet Perl, Part 2 Flow of Control and I/O. Perl Statements Lots of different ways to write similar statements –Can make your code look more like natural.
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
Transaction processing Book, chapter 6.6. Problem: With a single user…. you run a query, you get the results, you run the next, etc. But database life.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion.
E FFECTIVE C# 50 Specific Ways to Improve Your C# Second Edition Bill Wagner محمد حسین سلطانی.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
Optimistic Design 1. Guarded Methods Do something based on the fact that one or more objects have particular states  Make a set of purchases assuming.
Internet Software Development Controlling Threads Paul J Krause.
Maged M.Michael Michael L.Scott Department of Computer Science Univeristy of Rochester Presented by: Jun Miao.
Haskell - A Perspective Presented by Gábor Lipták April 2011.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Kernel Locking Techniques by Robert Love presented by Scott Price.
Shared Memory Consistency Models. SMP systems support shared memory abstraction: all processors see the whole memory and can perform memory operations.
CS162 Week 5 Kyle Dewey. Overview Announcements Reactive Imperative Programming Parallelism Software transactional memory.
The ATOMOS Transactional Programming Language Mehdi Amirijoo Linköpings universitet.
QIAN XI COS597C 10/28/2010 Explicit Concurrent Programming in Haskell.
SPL/2010 Guarded Methods and Waiting 1. SPL/2010 Reminder! ● Concurrency problem: asynchronous modifications to object states lead to failure of thread.
Summer Computing Workshop. Session 3 Conditional Branching  Conditional branching is used to alter the normal flow of execution depending on the value.
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
COSC 3407: Operating Systems Lecture 9: Readers-Writers and Language Support for Synchronization.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Optimistic Design CDP 1. Guarded Methods Do something based on the fact that one or more objects have particular states Make a set of purchases assuming.
CSE 341 Section 10 Subtyping, Review, and The Future.
Advanced Database CS-426 Week 6 – Transaction. Transactions and Recovery Transactions A transaction is an action, or a series of actions, carried out.
R 1 Transactional abstractions: beyond atomic update Tim Harris r.
Parallelism and Concurrency Koen Lindström Claessen Chalmers University Gothenburg, Sweden Patrik Jansson.
Parallelism and Concurrency
(Nested) Open Memory Transactions in Haskell
Software Transactional Memory
Clojure 6 Concurrency 20-Nov-18.
On transactions, and Atomic Operations
Multicore programming
Synchronization Hank Levy 1.
On transactions, and Atomic Operations
UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department
Clojure 4 Concurrency 24-Feb-19.
Concurrency and Immutability
Clojure 4 Concurrency 13-Apr-19.
Synchronization Hank Levy 1.
CSE 153 Design of Operating Systems Winter 19
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

Software Transactional Memory Steve Severance – Alpha Heavy Industries

Motivation Innovations in concurrency has not kept pace Still using locks Immutability has helped in Haskell

STM Basics Transactional Concurrency Atomicity – Results are visible all at once Isolation – Action unaffected by other threads Everything you need is in the stm package

Haskell and STM Exploits Three Haskell Features: – Purity (Transactions must be pure) – Monads – Immutability (Values are never modified) Utilizes the Type System – Anything involved in the transaction is marked (TVar, TChan, STM, etc…)

Basic Transaction Pattern atomically $ do … atomically evaluates the transaction main :: IO () main = do var <- newTVarIO False atomically $ do val <- readTVar var if val == False then writeTVar var True else return ()

Primitives TVar (Always has a Value) TMVar (Analogous to Regular MVar) TChan (Multicast Capabilities) TQueue (FIFO Queue) TBQueue (Bounded Queue) TSem (Semaphore)

Retrying Use the retry function to retry the transaction The transaction will only be run when one of the inputs has changed withdrawFunds :: TVar Account -> Money -> STM Money withdrawFunds accountVar amount = do account <- readTVar accountVar if (aBalance account) > amount then writeTVar accountVar account{aBalance = (aBalance account) `subtract` amount} >> return amount else retry

Choices orElse runs a second option if the first retrys withdrawEvil :: TVar Account -> TChan Account -> Money -> STM Money withdrawEvil accountVar nsfChan amount = do withdrawFunds accountVar amount `orElse` withdrawNonSufficientFunds accountVar nsfChan amount

Using Alternative You always wanted to use those cool operators Use instead of orElse

Dealing with Exceptions Revisiting the Atomic Guarantee – No need for rollback unlike MVar and Chan STM can throw and catch

Bounded Queues TBQueue limits its size Writers will block until space becomes available Useful for performance and memory management

Being Strict Use NFData (deepseq) We internally use special write functions to keep work from leaking across thread boundaries Transaction Time writeTVar’ :: NFData a => TVar a -> a -> STM () {-# INLINE writeTVar' #-} writeTVar' var val = rnf val `seq` writeTVar var val

Other Languages Clojure Scala C++ C#/.Net

References Composable Memory Transactions Beautiful Concurrency STM Retrospective for.Net Gists: – Sample 1 Sample 1