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.
Atomic Objects<br />
Atomic objects are <strong>new</strong> <strong>in</strong> C11 and similar to Java volatile variables.<br />
Atomic objects can safely be accessed without lock<strong>in</strong>g:<br />
_Atomic <strong>in</strong>t counter = ATOMIC_VAR_INIT(0);<br />
Thread 1 Thread 2<br />
counter++; counter++;<br />
Of course, you may need locks for o<strong>the</strong>r reasons to protect your data.<br />
Atomic objects have a global modification order and all threads see<br />
<strong>the</strong> same modification order.<br />
There is no total modification order of all atomic objects — different<br />
threads can see <strong>the</strong> stores to different atomic objects <strong>in</strong> different<br />
orders.<br />
Jonas Skeppstedt (js@cs.lth.se) Lecture 6 2013 3 / 70