Software Transactional Memory and Conditional Critical Regions

15
Software Transactional Memory and Conditional Critical Regions Word-Based Systems

description

Software Transactional Memory and Conditional Critical Regions. Word-Based Systems. Introduction: Motivation. Language Support for Lightweight Transactions (Harris & Fraser) Implement a declarative style of concurrency control where programmers indicate desired safety properties - PowerPoint PPT Presentation

Transcript of Software Transactional Memory and Conditional Critical Regions

Page 1: Software Transactional Memory and Conditional Critical Regions

Software Transactional Memory and Conditional Critical

Regions

Word-Based Systems

Page 2: Software Transactional Memory and Conditional Critical Regions

Introduction: Motivation

Language Support for Lightweight Transactions (Harris & Fraser)

Implement a declarative style of concurrency control where programmers indicate desired safety properties

New syntax implements Hoare’s Conditional Critical Region

Implemented using their STM

CS 5204 – Fall, 2009

Page 3: Software Transactional Memory and Conditional Critical Regions

CCR – Conditional Critical Region

CS 5204 – Fall, 2009

atomic (condition) { statements;}

1. Wait until Condition is satisfied2. Execute statements atomically

MeansMeans

public int get() { atomic (items != 0) { items --; return buffer[items]; }}

Pattern Example Use

Page 4: Software Transactional Memory and Conditional Critical Regions

CCR Implementation

Built on top of Software Transactional Memory Uses all traditional STM commands and STMWait

CS 5204 – Fall, 2009

boolean done = false;while (!done) { STMStart (); try { if (condition) { statements; done = STMCommit (); } else { STMWait(); } } catch (Throwable t) { done = STMCommit (); if (done) { throw t; } }}

Page 5: Software Transactional Memory and Conditional Critical Regions

STM Heap Structure

CS 5204 – Fall, 2009

.

.

.

Application Heap

.

.

.

.

A1: 7

A2: 100

A3: 200

A4: 500

A5: 600

.

.

.

Ownership Records

.

.

Version 1

Version 1

Version 1

Version 1

Page 6: Software Transactional Memory and Conditional Critical Regions

STM - Simple Transaction

CS 5204 – Fall, 2009

boolean done = false;while (true) {

STMStart();readvalues;if(STMValidate()){ statements; done = STMCommit(); if(done) { break; }}

}

Page 7: Software Transactional Memory and Conditional Critical Regions

Transaction Management

STMStart() STMAbort() STMCommit() STMValidate() STMWait()

CS 5204 – Fall, 2009

Page 8: Software Transactional Memory and Conditional Critical Regions

STM - Simple Transaction

CS 5204 – Fall, 2009

.

.

.

Application Heap

.

.

.

.

A1: 7

A2: 100

A3: 200

A4: 500

A5: 600

.

.

.

Ownership Records

.

.

Transaction Descriptor 1 Active

A2: (100,7) -> (300,8)

A1: (7,15) -> (7,15)Version 15

Version 7

Version x

Version y

Transaction Descriptor 1 Committed

A2: 300Version 8

1

1

Page 9: Software Transactional Memory and Conditional Critical Regions

STM Collisions - Abort

CS 5204 – Fall, 2009

.

.

.

Application Heap

.

.

.

.

A1: 7

A2: 100

A3: 200

A4: 500

A5: 600

.

.

.

Ownership Records

.

.

A2: (100,7) -> (300,8)

A1: (7,15) -> (7,15)

Version x

Version y

Transaction Descriptor 1 Active

A2: (100, 7) -> (9,8)

Transaction Descriptor 2 Active

2

1

1

Committing

A2’s Ownership Record is

unavailable! Commit Fails -

abort

A2’s Ownership Record is

unavailable! Commit Fails -

abort

Transaction Descriptor 2 Aborted

Page 10: Software Transactional Memory and Conditional Critical Regions

STM Collisions - Sleep

CS 5204 – Fall, 2009

boolean done = false;while (!done) { STMStart (); try { if (condition) { statements; done = STMCommit (); } else { STMWait(); } } catch (Throwable t) { done = STMCommit (); if (done) { throw t; } }}

Abort and waitAbort and wait

But when do I wake up?

atomic (condition) { statements;}

Page 11: Software Transactional Memory and Conditional Critical Regions

STM Sleep

CS 5204 – Fall, 2009

.

.

.

Application Heap

.

.

.

.

A1: 7

A2: 100

A3: 200

A4: 500

A5: 600

.

.

.

Ownership Records

.

.

A2: (100,7) -> (300,8)

A1: (7,15) -> (7,15)

Version x

Version y

Transaction Descriptor 1 Active

A1: (7,15) -> (7,15)

Committing

I failed my CCR condition, so I

aborted and fell asleep

I failed my CCR condition, so I

aborted and fell asleep

Transaction Descriptor 2 Asleep

Transaction Descriptor 1 Committed

Wake-upWake-up

Page 12: Software Transactional Memory and Conditional Critical Regions

STM Stealing - Optimization

CS 5204 – Fall, 2009

.

.

.

Application Heap

.

.

.

.

A1: 7

A2: 100

A3: 200

A4: 500

A5: 600

.

.

.

Ownership Records

.

.

A2: (100,7) -> (300,8)

A1: (7,15) -> (7,15)

Version x

Version y

Transaction Descriptor 1 Committed

A2: (300,8) -> (300,9)

A3: (200, 8) -> (8,9)

Transaction Descriptor 2 Active

2

1

1

Page 13: Software Transactional Memory and Conditional Critical Regions

STM – HTM Parallels: Data Copies

CS 5204 – Fall, 2009

Old DataHTM: XCOMMITSTM: Xaction Descriptor Entry

Original Memory

New DataHTM: XABORTSTM: Xaction Descriptor Entry

Copy Commit

Page 14: Software Transactional Memory and Conditional Critical Regions

STM – HTM Parallels: 3 Tier Implementation

CS 5204 – Fall, 2009

HTM STM

Page 15: Software Transactional Memory and Conditional Critical Regions

Questions

CS 5204 – Fall, 2009

????????