Software Transactional Memory Yoav Cohen Seminar in Distributed Computing Spring 2007 Yoav Cohen Seminar in Distributed Computing Spring 2007.

Slides:



Advertisements
Similar presentations
Time-based Transactional Memory with Scalable Time Bases Torvald Riegel, Christof Fetzer, Pascal Felber Presented By: Michael Gendelman.
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.
Concurrent programming for dummies (and smart people too) Tim Harris & Keir Fraser.
Optimistic Methods for Concurrency Control By : H.T. Kung & John T. Robinson Presenters: Munawer Saeed.
– R 7 :: 1 – 0024 Spring 2010 Parallel Programming 0024 Recitation Week 7 Spring Semester 2010.
Impossibilities for Disjoint-Access Parallel Transactional Memory : Alessia Milani [Guerraoui & Kapalka, SPAA 08] [Attiya, Hillel & Milani, SPAA 09]
1 Integrity Ioan Despi Transactions: transaction concept, transaction state implementation of atomicity and durability concurrent executions serializability,
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.
Transactional Locking Nir Shavit Tel Aviv University (Joint work with Dave Dice and Ori Shalev)
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: 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.
Software Transactional Memory Kevin Boos. Two Papers Software Transactional Memory for Dynamic-Sized Data Structures (DSTM) – Maurice Herlihy et al –
Nested Transactional Memory: Model and Preliminary Architecture Sketches J. Eliot B. Moss Antony L. Hosking.
TOWARDS A SOFTWARE TRANSACTIONAL MEMORY FOR GRAPHICS PROCESSORS Daniel Cederman, Philippas Tsigas and Muhammad Tayyab Chaudhry.
Transactional Memory Yujia Jin. Lock and Problems Lock is commonly used with shared data Priority Inversion –Lower priority process hold a lock needed.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
1 Lecture 21: Synchronization Topics: lock implementations (Sections )
CS510 Advanced OS Seminar Class 10 A Methodology for Implementing Highly Concurrent Data Objects by Maurice Herlihy.
Software Transactional Memory for Dynamic-sized Data Structures Maurice Herlihy, Victor Luchango, Mark Moir, William N. Scherer III Presented by: Irina.
CS510 Concurrent Systems Class 13 Software Transactional Memory Should Not be Obstruction-Free.
Synchronization in Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Language Support for Lightweight transactions Tim Harris & Keir Fraser Presented by Narayanan Sundaram 04/28/2008.
Software Transaction Memory for Dynamic-Sized Data Structures presented by: Mark Schall.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Transaction. A transaction is an event which occurs on the database. Generally a transaction reads a value from the database or writes a value to the.
An Introduction to Software Transactional Memory
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
Software Transactional Memory for Dynamic-Sized Data Structures Maurice Herlihy, Victor Luchangco, Mark Moir, William Scherer Presented by: Gokul Soundararajan.
A Qualitative Survey of Modern Software Transactional Memory Systems Virendra J. Marathe Michael L. Scott.
Transactional Memory Lecturer: Danny Hendler.  Speeding up uni-processors is harder and harder  Intel, Sun (RIP), AMD, IBM now focusing on “multi-core”
CS5204 – Operating Systems Transactional Memory Part 2: Software-Based Approaches.
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.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Internet Software Development Controlling Threads Paul J Krause.
Transactional Memory Lecturer: Danny Hendler. 2 2 From the New York Times…
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Wait-Free Multi-Word Compare- And-Swap using Greedy Helping and Grabbing Håkan Sundell PDPTA 2009.
Distributed systems Consensus Prof R. Guerraoui Distributed Programming Laboratory.
CS 3204 Operating Systems Godmar Back Lecture 7. 12/12/2015CS 3204 Fall Announcements Project 1 due on Sep 29, 11:59pm Reading: –Read carefully.
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.
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
MULTIVIE W Slide 1 (of 21) Software Transactional Memory Should Not Be Obstruction Free Paper: Robert Ennals Presenter: Emerson Murphy-Hill.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Multiprocessors – Locks
Maurice Herlihy, Victor Luchangco, Mark Moir, William N. Scherer III
Last Class: Canonical Problems
Part 2: Software-Based Approaches
Lecture 19: Coherence and Synchronization
Maurice Herlihy, Victor Luchangco, Mark Moir, William N. Scherer III
Outline Announcements Fault Tolerance.
Lecture 21: Synchronization and Consistency
Lecture: Coherence and Synchronization
Hybrid Transactional Memory
Software Transactional Memory Should Not be Obstruction-Free
Lecturer: Danny Hendler
Lecture 1: Introduction
Lecture: Coherence and Synchronization
Lecture 18: Coherence and Synchronization
Software Engineering and Architecture
UNIT -IV Transaction.
CSE 542: Operating Systems
Presentation transcript:

Software Transactional Memory Yoav Cohen Seminar in Distributed Computing Spring 2007 Yoav Cohen Seminar in Distributed Computing Spring 2007

Agenda  Motivation behind STM  Intro to STM  Static STM Implemented by Shavit and Touitou  Dynamic STM Implemented by Herlihy et al.  Motivation behind STM  Intro to STM  Static STM Implemented by Shavit and Touitou  Dynamic STM Implemented by Herlihy et al.

Motivation  Material covered so far:  Mutual Exclusion (Netanel)  Specifications for concurrent objects (Liza)  Registers for concurrent access (Yaniv)  Replace locks with HTM (Royi and Merav)  What else do we need?!  Material covered so far:  Mutual Exclusion (Netanel)  Specifications for concurrent objects (Liza)  Registers for concurrent access (Yaniv)  Replace locks with HTM (Royi and Merav)  What else do we need?!

HTM Shortcomings  Blocking - Can still deadlock  A thread is killed without releasing a lock  A thread is interrupted with a Page Fault while holding the lock  It’s hardware  Suggested at 1993 (Herlihy and Moss) - Not yet implemented  Blocking - Can still deadlock  A thread is killed without releasing a lock  A thread is interrupted with a Page Fault while holding the lock  It’s hardware  Suggested at 1993 (Herlihy and Moss) - Not yet implemented

STM 101  Same ideas as HTM  A thread executes a transaction  The transaction either commits or aborts  Different from HTM  Non-blocking - The system makes progress  Implemented in software - Available today  Same ideas as HTM  A thread executes a transaction  The transaction either commits or aborts  Different from HTM  Non-blocking - The system makes progress  Implemented in software - Available today

STM 101  A thread wants to change a shared object 1)The thread announces it 2)The thread copies the object to its private memory 3)The thread changes its private copy 4)The thread updates the changes  A thread wants to change a shared object 1)The thread announces it 2)The thread copies the object to its private memory 3)The thread changes its private copy 4)The thread updates the changes

STM 101  Two ways to update an object  Selective update - Update selected locations  Two ways to update an object  Selective update - Update selected locations Local copy Original object

STM 101  Two ways to update an object  Replacing the object all together  Two ways to update an object  Replacing the object all together Local copy Original object

Software Transactional Memory Nir Shavit, Dan Touitou (1995) A non-blocking concurrency framework implemented in software Uses the selective update approach A non-blocking concurrency framework implemented in software Uses the selective update approach

Overview Thread 1 Thread 2

The System Model We assume that every shared memory location supports these 4 operations:  Write i (L,v) - thread i writes v to L  Read i (L,v) - thread i reads v from L  LL i (L,v) - thread i reads v from L and marks that L was read by I  SC i (L,v) - thread i writes v to L and returns success if L is marked as read by i. Otherwise it returns failure. We assume that every shared memory location supports these 4 operations:  Write i (L,v) - thread i writes v to L  Read i (L,v) - thread i reads v from L  LL i (L,v) - thread i reads v from L and marks that L was read by I  SC i (L,v) - thread i writes v to L and returns success if L is marked as read by i. Otherwise it returns failure.

Thread class Rec { boolean stable = false; boolean,int status= (false,0); //can have two values … boolean allWritten = false; int version = 0; int size = 0; int locs[] = {null}; int oldValues[] = {null}; } class Rec { boolean stable = false; boolean,int status= (false,0); //can have two values … boolean allWritten = false; int version = 0; int size = 0; int locs[] = {null}; int oldValues[] = {null}; } Each thread is defined by an instance of a Rec class (short for record). The Rec instance defines the current transaction the thread is executing (only one transaction at a time)

The STM Object Memory Ownerships status version size locs[] oldValues[] Rec 1 status version size locs[] oldValues[] Rec 2 status version size locs[] oldValues[] Rec n This is the shared memory Pointers to threads

Flow of a transaction startTransactionThread i initialize transaction acquire Ownerships agreeOldValues calcNewValues updateMemory release Ownerships release Ownerships isInitiator? ThreadsSTM (Failure,failed loc) FT Initiate helping transaction to failed loc (isInitiator:=F) (Null, 0) Success Failure

The STM Object public class STM { int memory[]; Rec ownerships[]; public boolean, int[] startTranscation(Rec rec, int[] dataSet){...}; private void initialize(Rec rec, int[] dataSet) private void transaction(Rec rec, int version, boolean isInitiator) {...}; private void acquireOwnerships(Rec rec, int version) {...}; private void releaseOwnershipd(Rec rec, int version) {...}; private void agreeOldValues(Rec rec, int version) {...}; private void updateMemory(Rec rec, int version, int[] newvalues) {...}; } public class STM { int memory[]; Rec ownerships[]; public boolean, int[] startTranscation(Rec rec, int[] dataSet){...}; private void initialize(Rec rec, int[] dataSet) private void transaction(Rec rec, int version, boolean isInitiator) {...}; private void acquireOwnerships(Rec rec, int version) {...}; private void releaseOwnershipd(Rec rec, int version) {...}; private void agreeOldValues(Rec rec, int version) {...}; private void updateMemory(Rec rec, int version, int[] newvalues) {...}; }

Implementation public boolean, int[] startTranscation(Rec rec, int[] dataSet) { initialize(rec, dataSet); rec.stable = true; transaction(rec, rec.version, true); rec.stable = false; rec.version++; if (rec.status) return (true, rec.oldValues); else return false; } public boolean, int[] startTranscation(Rec rec, int[] dataSet) { initialize(rec, dataSet); rec.stable = true; transaction(rec, rec.version, true); rec.stable = false; rec.version++; if (rec.status) return (true, rec.oldValues); else return false; } This notifies other threads that I can be helped rec – The thread that executes this transaction. dataSet – The location in memory it needs to own.

Implementation private void transaction(Rec rec, int version, boolean isInitiator) { acquireOwnerships(rec, version); // try to own locations (status, failedLoc) = LL(rec.status); if (status == null) { // success in acquireOwnerships if (versoin != rec.version) return; SC(rec.status, (true,0)); } (status, failedLoc) = LL(rec.status); if (status == true) { // execute the transaction agreeOldValues(rec, version); int[] newVals = calcNewVals(rec.oldvalues); updateMemory(rec, version); releaseOwnerships(rec, version); } else { // failed in acquireOwnerships releaseOwnerships(rec, version); if (isInitiator) { Rec failedTrans = ownerships[failedLoc]; if (failedTrans == null) return; else {// execute the transaction that owns the location you want int failedVer = failedTrans.version; if (failedTrans.stable) transaction(failedTrans, failedVer, false); } private void transaction(Rec rec, int version, boolean isInitiator) { acquireOwnerships(rec, version); // try to own locations (status, failedLoc) = LL(rec.status); if (status == null) { // success in acquireOwnerships if (versoin != rec.version) return; SC(rec.status, (true,0)); } (status, failedLoc) = LL(rec.status); if (status == true) { // execute the transaction agreeOldValues(rec, version); int[] newVals = calcNewVals(rec.oldvalues); updateMemory(rec, version); releaseOwnerships(rec, version); } else { // failed in acquireOwnerships releaseOwnerships(rec, version); if (isInitiator) { Rec failedTrans = ownerships[failedLoc]; if (failedTrans == null) return; else {// execute the transaction that owns the location you want int failedVer = failedTrans.version; if (failedTrans.stable) transaction(failedTrans, failedVer, false); } rec – The thread that executes this transaction. version – Serial number of the transaction. isInitiator – Am I the initiating thread or the helper? Another thread own the locations I need and it hasn’t finished its transaction yet. So I go out and execute its transaction in order to help it.

Implementation private void acquireOwnerships(Rec rec, int version) { for (int j=1; j<=rec.size; j++) { while (true) do { int loc = locs[j]; if LL(rec.status) != null return; // transaction completed by some other thread Rec owner = LL(ownerships[loc]); if (rec.version != version) return; if (owner == rec) break;// location is already mine if (owner == null) {// acquire location if ( SC(rec.status, (null, 0)) ) { if ( SC(ownerships[loc], rec) ) { break; } else {// location is taken by someone else if ( SC(rec.status, (false, j)) ) return; } private void acquireOwnerships(Rec rec, int version) { for (int j=1; j<=rec.size; j++) { while (true) do { int loc = locs[j]; if LL(rec.status) != null return; // transaction completed by some other thread Rec owner = LL(ownerships[loc]); if (rec.version != version) return; if (owner == rec) break;// location is already mine if (owner == null) {// acquire location if ( SC(rec.status, (null, 0)) ) { if ( SC(ownerships[loc], rec) ) { break; } else {// location is taken by someone else if ( SC(rec.status, (false, j)) ) return; } If I’m not the last one to read this field, it means that another thread is trying to execute this transaction. Try to loop until I succeed or until the other thread completes the transaction

Implementation private void agreeOldValues(Rec rec, int version) { for (int j=1; j<=rec.size; j++) { int loc = locs[j]; if ( LL(rec.oldvalues[loc]) != null ) { if (rec.version != version) return; SC(rec.oldvalues[loc], memory[loc]); } private void updateMemory(Rec rec, int version, int[] newvalues) { for (int j=1; j<=rec.size; j++) { int loc = locs[j]; int oldValue = LL(memory[loc]); if (rec.allWritten) return; // work is done if (rec.version != version) return; if (oldValue != newValues[j]) SC(memory[loc], newValues[j]); } if (! LL(rec.allWritten) ) { if (rec.version != version) SC(rec.allWritten, true); } private void agreeOldValues(Rec rec, int version) { for (int j=1; j<=rec.size; j++) { int loc = locs[j]; if ( LL(rec.oldvalues[loc]) != null ) { if (rec.version != version) return; SC(rec.oldvalues[loc], memory[loc]); } private void updateMemory(Rec rec, int version, int[] newvalues) { for (int j=1; j<=rec.size; j++) { int loc = locs[j]; int oldValue = LL(memory[loc]); if (rec.allWritten) return; // work is done if (rec.version != version) return; if (oldValue != newValues[j]) SC(memory[loc], newValues[j]); } if (! LL(rec.allWritten) ) { if (rec.version != version) SC(rec.allWritten, true); } Copy the dataSet to my private space Selectively update the shared memory

Proving the Non-blocking Property  Every failing transaction has a thread which writes Failure to its status field.  Intuition – Let’s show that a situation where the system is stuck can’t happen.  Proof outline – Assume the system is stuck and derive a contradiction.  Every failing transaction has a thread which writes Failure to its status field.  Intuition – Let’s show that a situation where the system is stuck can’t happen.  Proof outline – Assume the system is stuck and derive a contradiction.

Proving the Non-blocking Property  Claim (No proof): Given a failing transaction, in which the failing thread failed to acquire a location A, all threads executing it will never acquire ownership of a location which is higher than the A.

Proving the Non-blocking Property  The system is stuck – There are infinitely many transactions that do not succeed. 1)Number of failing transactions is finite – The other ones are stuck in a loop 2)Number of failing transactions is infinite  The system is stuck – There are infinitely many transactions that do not succeed. 1)Number of failing transactions is finite – The other ones are stuck in a loop 2)Number of failing transactions is infinite

Proving the Non-blocking Property  Number of failing transactions is finite  Other ones are stuck in the loop in acquireOwnerships.  This can only happen if some threads are trying to acquire the same location for the same transaction.  This state can’t be reached (on the board).  A contradiction.  Number of failing transactions is finite  Other ones are stuck in the loop in acquireOwnerships.  This can only happen if some threads are trying to acquire the same location for the same transaction.  This state can’t be reached (on the board).  A contradiction. T1 (Loop) T2 (Fail) T3 (Loop) … Tn (Loop)

Proving the Non-blocking Property  Number of failing transactions is infinite  Since the number of locations is finite, there exists at least one location which is a failing location infinitely often.  Choose A, the highest of those locations.  Intuition – If A is a failing location infinitely often, there are infinitely many transactions who acquired A and failed.  Contradiction – A is not the highest location.  Number of failing transactions is infinite  Since the number of locations is finite, there exists at least one location which is a failing location infinitely often.  Choose A, the highest of those locations.  Intuition – If A is a failing location infinitely often, there are infinitely many transactions who acquired A and failed.  Contradiction – A is not the highest location.

Limitations of STM  Static - Information about transactions is required beforehand:  Size  DataSet  A static software transactional memory is limited only to predefined transactions and data structures.  Static - Information about transactions is required beforehand:  Size  DataSet  A static software transactional memory is limited only to predefined transactions and data structures.

Performance of STM  In stable scenarios, it has a lower throughput than locks.  But, it is non-blocking, hence the system will always progress.  In stable scenarios, it has a lower throughput than locks.  But, it is non-blocking, hence the system will always progress.

Dynamic STM Herlihy, Moir, Luchangco, Scherer (2003) Suited for Dynamic-Sized Data Structures Uses the pointers swap technique Introduces a weaker non-blocking property called obstruction freedom Introduces Contention Managers Suited for Dynamic-Sized Data Structures Uses the pointers swap technique Introduces a weaker non-blocking property called obstruction freedom Introduces Contention Managers

Thread  A thread announces the start of a transaction  A thread executes a series of operations on shared objects  A thread tries to commit the transaction public class TMThread { public void beginTransaction(); public void abortTransaction(); public boolean commitTransaction(); }  A thread announces the start of a transaction  A thread executes a series of operations on shared objects  A thread tries to commit the transaction public class TMThread { public void beginTransaction(); public void abortTransaction(); public boolean commitTransaction(); }

Flow of a transaction TMThread i ThreadsConcurrent Dynamic-Sized Data Structure Shared Object someMethod() Thread.startTransaction() SharedObject.open(WRITE) … SharedObject.release() Thread.commitTransaction() end someMethod() Committing a transaction is done atomically!

A concurrent system View from above TMThread j Threads TMThread k TMThread i TMThread m

Opening a shared object Intuition:  When you open a shared object you get a clone.  You change the clone  When you commit the transaction the clone replaces the original object Intuition:  When you open a shared object you get a clone.  You change the clone  When you commit the transaction the clone replaces the original object

Structure of a shared object Locator transaction oldObject newObject Data TMObject ACTIVE Transaction

Implementation class Transaction { enum Status {ACTIVE, COMMITTED, ABORTED}; Status status = Status.ACTIVE; } class Transaction { enum Status {ACTIVE, COMMITTED, ABORTED}; Status status = Status.ACTIVE; } Initialized to ACTIVE

Implementation class TMObject { // internal classes enum AccessType {WRITE, READ}; class Locator { Transaction transaction; Object newObject; Object oldObject; } // data members Locator locator; // methods public void open(AccessType type) throws DeniedException {}; } class TMObject { // internal classes enum AccessType {WRITE, READ}; class Locator { Transaction transaction; Object newObject; Object oldObject; } // data members Locator locator; // methods public void open(AccessType type) throws DeniedException {}; } Ways to access the object Pointers to the object’s data Access the object

Opening a shared object for Writing public Object open(AccessType type) throws DeniedException { if (type==AccessType.WRITE) { Locator newLocator = new Locator(); newLocator.transaction = TMThread.getCurrentTransaction(); if (locator.transaction.status==Status.ACTIVE) { resolveConflict(); } else { if (locator.transaction.status==Status.COMMITTED) { newLocator.oldObject = locator.newObject; newLocator.newObject = locator.newObject.clone(); } else if (locator.transaction.status==Status.ABORTED) { newLocator.oldObject = locator.oldObject; newLocator.newObject = locator.oldObject.clone(); } validateTransaction(newLocator.transaction) return newLocator.newObject; } public Object open(AccessType type) throws DeniedException { if (type==AccessType.WRITE) { Locator newLocator = new Locator(); newLocator.transaction = TMThread.getCurrentTransaction(); if (locator.transaction.status==Status.ACTIVE) { resolveConflict(); } else { if (locator.transaction.status==Status.COMMITTED) { newLocator.oldObject = locator.newObject; newLocator.newObject = locator.newObject.clone(); } else if (locator.transaction.status==Status.ABORTED) { newLocator.oldObject = locator.oldObject; newLocator.newObject = locator.oldObject.clone(); } validateTransaction(newLocator.transaction) return newLocator.newObject; } Trying to access an already open object Make sure the transaction is still active and its read table is up to date

Opening a shared object for Writing COMMITTED locator transaction oldObject newObject Data newLocator transaction oldObject newObject Data clone() ACTIVE Because the last transaction committed we take its changes

Opening a shared object for Writing ABORTED locator transaction oldObject newObject Data newLocator transaction oldObject newObject Data clone() ACTIVE Because the last transaction aborted we discard its changes

Opening a shared object for Reading  Intuition: Just have to make sure threads read the most updated version  Practice:  We keep a Thread Local table of the objects we opened for read and their latest version  We keep a counter for each object to track number of open and release invocations  We increment the counter when open is called  We decrement the counter when release is called. If counter == 0 we remove the object from the table  Intuition: Just have to make sure threads read the most updated version  Practice:  We keep a Thread Local table of the objects we opened for read and their latest version  We keep a counter for each object to track number of open and release invocations  We increment the counter when open is called  We decrement the counter when release is called. If counter == 0 we remove the object from the table

Opening a shared object for Reading class ReadTable { class ReadTableItem { Object object; int counter; } Map readTable; void insert(int objID, Object objInst) { if ( readTable.containsKey(objID) ) { ReadTableItem item = readTable.get(objID); item.counter++; } else { ReadTableItem newItem = new ReadTableItem(objInst,1); readTable.put(objID, newItem); } void remove(int objID) {... } class ReadTable { class ReadTableItem { Object object; int counter; } Map readTable; void insert(int objID, Object objInst) { if ( readTable.containsKey(objID) ) { ReadTableItem item = readTable.get(objID); item.counter++; } else { ReadTableItem newItem = new ReadTableItem(objInst,1); readTable.put(objID, newItem); } void remove(int objID) {... } The object and its counter This is how we open an object for reading.

Opening a shared object for Reading public class TMThread { ThreadLocal readTable; public void beginTransaction(); public void abortTransaction(); public boolean commitTransaction(); } public class TMThread { ThreadLocal readTable; public void beginTransaction(); public void abortTransaction(); public boolean commitTransaction(); } Each thread has a read table

Committing a transaction Commiting a transaction requires 2 steps: 1.Validating the read table of the thread 2.Using Compare&Swap to change the transaction status from ACTIVE to COMMITED Commiting a transaction requires 2 steps: 1.Validating the read table of the thread 2.Using Compare&Swap to change the transaction status from ACTIVE to COMMITED

Example public class SomeDynamicSizedDataStructure { TMObject data; public boolean insert(Element elem) { TMThread thread = (TMThread) Thread.getCurrentThread(); while (true) { // loop until commited or aborted thread.beginTransaction(); boolean result; try { data.open(WRITE); /* Insert elem to data here */ data.release(); result = true; } catch (DeniedException e) { /* Could not open a shared object */ result = fasle; } if (thread.commitTransaction() == true) return result; } public class SomeDynamicSizedDataStructure { TMObject data; public boolean insert(Element elem) { TMThread thread = (TMThread) Thread.getCurrentThread(); while (true) { // loop until commited or aborted thread.beginTransaction(); boolean result; try { data.open(WRITE); /* Insert elem to data here */ data.release(); result = true; } catch (DeniedException e) { /* Could not open a shared object */ result = fasle; } if (thread.commitTransaction() == true) return result; }

Non-blocking  The DSTM implementation ensures a non- blocking property called obstruction- freedom.  It means that any thread that runs alone for a long enough time makes progress.  Weaker than lockout-freedom of STM  The DSTM implementation ensures a non- blocking property called obstruction- freedom.  It means that any thread that runs alone for a long enough time makes progress.  Weaker than lockout-freedom of STM

Contention Management  Contention Management policy - What does a thread do when it encounters a conflict?  The DSTM implementation has an extension mechanism to allow for different contention management policies.  These extensions are called Contention Managers.  Contention Management policy - What does a thread do when it encounters a conflict?  The DSTM implementation has an extension mechanism to allow for different contention management policies.  These extensions are called Contention Managers.

Contention Managers  Each thread has a reference to a Contention Manager.  Whenever the thread encounters a conflict, it advices with its Contention Manger to decide what to do.  When a conflict is encountered a thread can either abort itself, wait or abort the other transaction.  Each thread has a reference to a Contention Manager.  Whenever the thread encounters a conflict, it advices with its Contention Manger to decide what to do.  When a conflict is encountered a thread can either abort itself, wait or abort the other transaction.

Summary  Pros and Cons of STM  Pros and Cons of DSTM  Discussion – what should the future concurrency framework look like?  Pros and Cons of STM  Pros and Cons of DSTM  Discussion – what should the future concurrency framework look like?