09.TransactionalMemory

09.TransactionalMemory - Synchronizationvia Transactions 1...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Synchronization via Transactions
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Concurrency Quiz If two threads execute this program concurrently, how many different final values of X are there? Initially, X == 0. void increment() { int temp = X; temp = temp + 1; X = temp; } void increment() { int temp = X; temp = temp + 1; X = temp; } Thread 1 Thread 2 Answer: A.0 B.1 C.2 D.More than 2
Background image of page 2
3 Schedules/Interleavings Model of concurrent execution Interleave statements from each thread into a single thread If any interleaving yields incorrect results, some synchronization is needed tmp1 = X; tmp1 = tmp1 + 1; X = tmp1; tmp2 = X; tmp2 = tmp2 + 1; X = tmp2; Thread 1 Thread 2 tmp1 = X; tmp2 = X; tmp2 = tmp2 + 1; tmp1 = tmp1 + 1; X = tmp1; X = tmp2; If X==0 initially, X == 1 at the end. WRONG result!
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Locks fix this with Mutual Exclusion Is mutual exclusion really what we want? Don’t we just want the correct result? Some interleavings may give the correct result. Why can’t we keep these? void increment() { lock.acquire(); int temp = X; temp = temp + 1; X = temp; lock.release(); }
Background image of page 4
5 Providing atomicity and isolation directly Critical regions need atomicity and isolation Definition : An atomic operation’s effects either all happen or none happen. Money transfer either debits one acct and credits the other, or no money is transferred Definition : An isolated operation is not affected by concurrent operations. Partial results are not visible This allows isolated operations to be put in a single, global order
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Providing atomicity and isolation directly Implementing atomicity and isolation Changes to memory are buffered (isolation) Other processors see old values (isolation) If something goes wrong (e.g., exception), system rolls back state to start of critical section (atomicity) When critical region ends, changes become visible all at once (atomicity) Hardware Processor support for buffering and committing values Software Runtime system buffers and commits values
Background image of page 6
7 Transactions Transaction begin (xbegin) Start of critical region Transaction end (xend) End of critical region xbegin/xend can be implicit with atomic{} Transaction restart (or abort) User decides to abort transaction In Java throwing an exception aborts the transaction atomic { acctA -= 100; acctB += 100; } Transaction to transfer $100 from acctA to acctB.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Atomicity and Isolation AcctA starts with $150 Different blocks to update balance Overnight batch process to read/process/write accounts Debit $100 Telephone transaction to read/process/write quickly Debit $90 Isolation guarantees that phone update is not lost It is allowed by atomicity In fact, both transactions (in either order) should result in overdraft AcctA = -$40
Background image of page 8
9 Atomicity and Isolation AcctA starts with $150
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 03/09/2012.

Page1 / 25

09.TransactionalMemory - Synchronizationvia Transactions 1...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online