E if your program contains a data race all bets are o

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ite Note: Many languages that define memory consistency models do so only for programs without data races –  i.e., “If your program contains a data race, all bets are off” –  Personally, this has always been a liLle discouraging to me (a) it’d be easy to have a data race and never realize it (so “blammo!”?) (b) intuiCvely, if you hit a data race, there are more and less likely things that will occur –  but, in the defense of languages, how much can they really constrain/ define all future HW and compiler opCmizaCons? CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain 44 Preven3ng Data Races •  The key to prevenCng data races is synchroniza!on –  i.e., coordinate between tasks rather than having them race to memory independently of one another •  The specific synchronizaCon mechanisms available and semanCcs they impose tend to be language-­‐/ compiler-­‐specific CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain 45 A Common Mechanism: Memory Fences Memory Fences: –  Intrinsic operaCons that have specific semanCcs w.r.t. memory accesses •  also known as memory barriers, or simply “fences”, … –  SomeCmes specified in language, other Cmes by compilers •  e.g., C, being sequenCal, hadn’t defined one, so gcc did –  A typical example of a fence: •  execuCon won’t proceed unCl all outstanding loads/stores complete •  compiler cannot reorder loads/stores across fence operaCons –  Specifics vary with implementaCon –  Granularity is an important issue to pay aLenCon to •  w.r.t. what subset of the hardware? •  w.r.t. ops from the task or process or program or …? CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain 46 Memory Consistency in Chapel Two part story: 1) TradiConal variables have a relaxed consistency model var data: [1..size] int, flag = false; cobegin { { // forall i in 1..size do data[i] = i; flag = true; } { // while (!flag) do ; writeln(“data is:”, data); } } CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain task 1 // write data // signal data written task 2 // spin on flag // unsafe read! 47 Memory Consistency in Chapel Two part story: 2) OperaCons on sync/single variables imply a fence: var data: [1..size] int, flag$: sync bool; cobegin { { // forall i in 1..size do data[i] = i; flag$ = true; } { // const flagval = flag$; writeln(“data is:”, data); } } CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain task 1 // write data // signal data written task 2 // block on flag$ // read will be safe // due to fence 48 Memory Consistency Models in Adopted Languages Java: the first major language to adopt one? –  circa 2005 (?) –  the touchstone of language-­‐based MCMs –  arguably overkill for other languages due to security requirements C/C++: Playing catch-­‐up – adopted in C11/C++11 –  Defined reasonably similarly for both C#: Seems to have one, I’m not familiar with the history CSEP 524: Parallel ComputaCon Winter 2013: Chamberlain 49 Resources For Furthe...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online