Threads in the new ISO C Standard from 2011
Threads in the new ISO C Standard from 2011
Threads in the new ISO C Standard from 2011
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Answer: Yes<br />
The code may execute <strong>in</strong> <strong>the</strong> follow<strong>in</strong>g order:<br />
atomic_store_explicit(&b, 42, memory_order_relaxed); // Thread 2<br />
x = atomic_load_explicit(&b, memory_order_relaxed); // Thread 1<br />
atomic_store_explicit(&a, x, memory_order_relaxed); // Thread 1<br />
y = atomic_load_explicit(&a, memory_order_relaxed); // Thread 2<br />
With relaxed memory order<strong>in</strong>g and no dependency <strong>the</strong> store can be<br />
reordered and execute first.<br />
There is a dependency through <strong>the</strong> variable x between <strong>the</strong> accesses by<br />
Thread 1 — so <strong>the</strong>y may not be reordered, luckily.<br />
We will see more about dependences below.<br />
Jonas Skeppstedt (js@cs.lth.se) Lecture 6 2013 11 / 70