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.

134<br />

ultimately faulty specification (see Section 5.10.3). In this chapter we explain the problem<br />

as precisely as possible, we show that the restriction of thin-air values in C/<strong>C++11</strong><br />

invalidates the accepted implementations of atomic accesses, <strong>and</strong> we explore alternative<br />

solutions, making some concrete suggestions.<br />

5.10.1 Thin-air values, informally<br />

Precisely defining thin-air values is the very problem that the language faces, so instead<br />

of a definition of the term, this chapter offers a series of examples that explore the design<br />

space for the memory model’s restriction of thin-air values. Before the first example of an<br />

execution with a thin-air value, recall the load-buffering test, repeated below. <strong>The</strong> model<br />

allows the read in each thread to read from the write in the other, completing a cycle in<br />

sb union rf. This behaviour is not only allowed by the C/<strong>C++11</strong> memory model, it is<br />

also permitted for analogous programs on both the ARM <strong>and</strong> IBM Power architectures,<br />

<strong>and</strong> observable on ARM processors. If load buffering were forbidden by the language, the<br />

lightweight implementations of relaxed accesses would have to be strengthened for Power<br />

<strong>and</strong> ARM.<br />

int main() {<br />

atomic_int x = 0;<br />

atomic_int y = 0;<br />

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

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

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

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

}}}<br />

return 0;<br />

}<br />

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

sb sb<br />

rf rf<br />

d:W RLX y=1 f:W RLX x=1<br />

Allowed by Power <strong>and</strong> ARM architectures, <strong>and</strong> observed on ARM,<br />

so C/<strong>C++11</strong> should allow this.<br />

Many of the examples of thin-air values in this section will, at their core, contain<br />

the cyclic shape of this load-buffering execution. <strong>The</strong> first example of a thin-air value,<br />

LB+data+data, augments the basic load-buffering program by adding data-dependencies<br />

from the writes to the reads in each thread:

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

Saved successfully!

Ooh no, something went wrong!