

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























2
Ensure that a data structure is manipulated by only one thread at a time
4
- Transactional memory (TM) - support arbitrary atomic actions on multi-word shared data - transactions that don’t conflict run uninterrupted in parallel - transactions that conflict abort and retry - no need for programmer to worry about deadlock! - note: repeated aborts can waste resources and hurt performance + easy to use, well-understood metaphor - high overhead in software; BG/Q has first HTM (Spring 2012) ± **subject of much active research
5
Coarse Locks Canned NBS Fine Lock Ad Hoc NBS HW TM Software TM (STM)
Figure credit: William Scherer
7
Classical locking algorithms using load and store
8
10
class Lock1: public Lock { private: ! volatile bool flag[2]; ! public: void acquire() { int other_threadid = 1 - self_threadid; flag[self_threadid] = true; while (flag[other_threadid] == true); } void release() { flag[self_threadid] = false; } }
11
0
1
assume that initially both flags are false
13
class Lock1: public Lock { private: ! volatile bool flag[2]; ! public: void acquire() { int other_threadid = 1 - self_threadid; flag[self_threadid] = true; while (flag[other_threadid] == true); } void release() { flag[self_threadid] = false; } }
14
16
class Lock2: public Lock { private: ! volatile int victim; ! public: void acquire() { victim = self_threadid; while (victim == self_threadid); // busy wait } void release() { } }
17
19
class Lock2: public Lock { private: ! volatile int victim; ! public: void acquire() { victim = self_threadid; while (victim == self_threadid); // busy wait } void release() { } }
20