06.08.2013 Views

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

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Us<strong>in</strong>g Atomic Objects<br />

Members of an atomic struct/union may not be accessed <strong>in</strong>dividually.<br />

The whole struct must first be copied to a non-atomic variable of<br />

compatible type.<br />

The ++, --, and compound assignment operators (e.g. +=) are atomic<br />

read-modify-write operations.<br />

The size of atomic and non-atomic compatible types is typically<br />

different as well as <strong>the</strong> alignment requirements.<br />

The memory order<strong>in</strong>g when us<strong>in</strong>g <strong>the</strong>se operators is sequential<br />

consistency, which means costly memory fences are used.<br />

We will see functions for perform<strong>in</strong>g <strong>the</strong> same atomic operations<br />

which use relaxed memory order<strong>in</strong>g and may be preferable.<br />

Recall that alignment requirement refers to that for example a four<br />

byte <strong>in</strong>t must be given an address that is a multiple of four etc.<br />

Jonas Skeppstedt (js@cs.lth.se) Lecture 6 2013 5 / 70

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!