29.11.2015 Views

The C11 and C++11 Concurrency Model

1ln7yvB

1ln7yvB

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

80<br />

a:W NA x=0<br />

sb<br />

rf<br />

b:W NA y=0<br />

rf<br />

rf<br />

int main() {<br />

}<br />

atomic_int x = 0;<br />

atomic_int y = 0;<br />

{{{ x.store(1,relaxed);<br />

||| y.store(1,relaxed);<br />

||| { r1 = x.load(relaxed);<br />

r2 = (*(&y+r1-r1)).load(relaxed); }<br />

||| { r3 = y.load(relaxed);<br />

}}}<br />

return 0;<br />

r4 = (*(&x+r3-r3)).load(relaxed); }<br />

rf<br />

c:W RLX x=1 d:W RLX y=1 e:R RLX x=1 g:R RLX y=1<br />

sb<br />

f:R RLX y=0<br />

sb<br />

h:R RLX x=0<br />

Each reader thread sees the writes occur in a different order. <strong>The</strong> Power <strong>and</strong> ARM<br />

architectures allow this behaviour because they can propagate the writes to the reader<br />

threads individually <strong>and</strong> out of order. C/<strong>C++11</strong> also violates multi-copy atomicity here:<br />

the execution above is allowed by the memory model. <strong>The</strong>re is no speculation mechanism<br />

to disable in C/<strong>C++11</strong>, nor is there propagation — the execution is allowed because none<br />

of the rules of the model forbid it. Note that the dependencies in this example could be<br />

optimised away by a C/<strong>C++11</strong> compiler.<br />

Write-read causality, WRC<br />

WRC (taken from Boehm <strong>and</strong> Adve [37]), is similar to MP, in that apparent causality<br />

implied by reading across threads is not enough to create order. This time the program<br />

demonstrates that a reads-from edge does not order two reads from the same location:<br />

the read on the centre thread sees the write on the first thread, whereas the read in the<br />

right-h<strong>and</strong> thread does not.

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

Saved successfully!

Ooh no, something went wrong!