Software Transactional Memory and Conditional Critical Regions WordBased
Software Transactional Memory and Conditional Critical Regions Word-Based Systems
Introduction: Motivation n n 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
CCR – Conditional Critical Region atomic (condition) { statements; } public int get() { atomic (items != 0) { items --; return buffer[items]; } } Means 1. Wait until Condition is satisfied 2. Execute statements atomically Pattern Example Use CS 5204 – Fall, 2009
CCR Implementation n n Built on top of Software Transactional Memory Uses all traditional STM commands and STMWait boolean done = false; while (!done) { STMStart (); try { if (condition) { statements; done = STMCommit (); } else { STMWait(); } } catch (Throwable t) { done = STMCommit (); if (done) { throw t; } } } CS 5204 – Fall, 2009
STM Heap Structure Application Heap. . Ownership Records Version 1 A 1: 7 A 2: 100 Pairing Version 1 Algorith m. . (Hash? ) A 3: 200. . A 4: 500 Version 1 A 5: 600. . Version 1. . CS 5204 – Fall, 2009
STM - Simple Transaction boolean done = false; while (true) { STMStart(); readvalues; if(STMValidate()){ statements; done = STMCommit(); if(done) { break; } } } CS 5204 – Fall, 2009
Transaction Management n n n STMStart() STMAbort() STMCommit() STMValidate() STMWait() CS 5204 – Fall, 2009
STM - Simple Transaction Application Heap. . A 1: 7 A 2: 300 100 A 3: 200. . . Ownership Records Transaction Descriptor 1 Active Committed 1 Version 15 A 1: (7, 15) -> (7, 15) 7 1 Version 8 A 2: (100, 7) -> (300, 8) . . . A 4: 500 Version x A 5: 600. . Version y. . CS 5204 – Fall, 2009
STM Collisions - Abort Committing Application Heap. . A 1: 7 Ownership Records 1 A 1: (7, 15) -> (7, 15) A 2: 100 A 2: (100, 7) -> (300, 8) 2 1 A 3: 200. . . A 4: 500 A 5: 600. . Transaction Descriptor 1 Active A 2’s Ownership Record is unavailable! Commit Fails abort . . . Transaction Descriptor 2 Active Aborted Version x Version y. . CS 5204 – Fall, 2009 A 2: (100, 7) -> (9, 8)
STM Collisions - Sleep atomic (condition) { statements; } 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 wait But when do I wake up? CS 5204 – Fall, 2009
STM Sleep Committing Application Heap. . Ownership Records Wake-up Transaction Descriptor 1 Active Committed A 1: 7 A 1: (7, 15) -> (7, 15) A 2: 100 A 2: (100, 7) -> (300, 8) A 3: 200. . . I failed my CCR condition, so I aborted and fell asleep . . . A 4: 500 Version x A 5: 600. . Version y. . CS 5204 – Fall, 2009 Transaction Descriptor 2 Asleep A 1: (7, 15) -> (7, 15)
STM Stealing - Optimization Application Heap. . A 1: 7 Ownership Records 1 A 1: (7, 15) -> (7, 15) A 2: 100 A 2: (100, 7) -> (300, 8) 2 1 A 3: 200. . . Transaction Descriptor 1 Committed . . . A 4: 500 Version x A 5: 600. . Version y. . CS 5204 – Fall, 2009 Transaction Descriptor 2 Active A 3: (200, 8) -> (8, 9) A 2: (300, 8) -> (300, 9)
STM – HTM Parallels: Data Copies Old Data New Data HTM: XCOMMIT STM: Xaction Descriptor Entry HTM: XABORT STM: Xaction Descriptor Entry Copy Original Memory CS 5204 – Fall, 2009 Commit
STM – HTM Parallels: 3 Tier Implementation HTM STM Transaction Runtime Transaction Descriptors Snoopy Cache Ownership Records Shared Memory Application Heap CS 5204 – Fall, 2009
Questions ? ? ? ? CS 5204 – Fall, 2009
- Slides: 15