29.11.2015 Views

The C11 and C++11 Concurrency Model

1ln7yvB

1ln7yvB

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

31<br />

Executions of this program might read from y any number of times before seeing the<br />

value 1, or they may never see the value 1. We focus on executions where the first read<br />

of y reads the value 1, so we simplify the test to remove the loop:<br />

int x = 0;<br />

int y = 0;<br />

x = 1; r1 = y;<br />

y = 1; r2 = x;<br />

In the sequentially consistent memory model, the behaviour of the program is given<br />

by the set of all interleavings of the memory accesses, as presented in the table below:<br />

Interleaving<br />

Outcome<br />

x = 0; y = 0; x = 1; y = 1; r1 = y; r2 = x r1 = 1, r2 = 1<br />

x = 0; y = 0; x = 1; r1 = y; y = 1; r2 = x<br />

x = 0; y = 0; r1 = y; x = 1; y = 1; r2 = x<br />

r1 = 0, r2 = 1<br />

x = 0; y = 0; x = 1; r1 = y; r2 = x; y = 1<br />

x = 0; y = 0; r1 = y; x = 1; r2 = x; y = 1<br />

x = 0; y = 0; r1 = y; r2 = x; x = 1; y = 1 r1 = 0, r2 = 0<br />

Note that the outcome 1/0 is not allowed under sequential consistency or x86 — the<br />

first-in-first-out nature of the write buffers makes it impossible to see the second write<br />

without the first already having flushed to memory. On Power, the relaxed behaviour<br />

could be introduced by any of the following three architectural optimisations:<br />

• <strong>The</strong>lefth<strong>and</strong>thread’swritesmightbecommittedtomemoryoutoforder, byreordering<br />

the stores.<br />

• <strong>The</strong> right h<strong>and</strong> thread’s reads might be performed out of order by some speculation<br />

mechanism.<br />

• <strong>The</strong> memory subsystem might propagate the writes to the other thread out-of-order.<br />

<strong>The</strong> Power <strong>and</strong> ARM architectures expose all three sorts of reordering mentioned<br />

above, <strong>and</strong> produce the result 1/0 on the message-passing example.<br />

<strong>The</strong> Power <strong>and</strong> ARM abstract machine Sarkar et al. define the Power <strong>and</strong> ARM<br />

architecturememorymodel asan abstractmachine. This machineissplit between threadlocal<br />

details such as speculation, <strong>and</strong> memory-subsystem details such as write propagation.<br />

Threads can make write, read <strong>and</strong> barrier requests, <strong>and</strong> the memory subsystem<br />

can respond with barrier acknowledgements <strong>and</strong> read responses. Read requests, rather<br />

than containing a simple value, are associated with a particular write that is identified<br />

by a read-response event. Each read-request from a thread results in an immediate readresponse<br />

from the storage subsystem.

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

Saved successfully!

Ooh no, something went wrong!