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.

90<br />

int main() {<br />

int x = 0; atomic_int y = 0;<br />

{{{ { x = 1;<br />

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

||| { while (y.load(acquire) == 1);<br />

r1 = x; }<br />

}}}<br />

return 0;<br />

}<br />

c:W NA x=1<br />

rf<br />

e:R ACQ y=1<br />

sb sb<br />

rf,sw<br />

d:W REL y=1 f:R NA x=1<br />

On the Power architecture, the compilation mapping places an lwsync barrier above<br />

the write to the atomic location. It is the fact that the barrier occurs between the nonatomic<br />

write <strong>and</strong> the atomic write that preserves the ordering on the hardware. Inserting<br />

a relaxed write to the same location after the release write gives us the following program<br />

(the rs edge will be explained below):<br />

int main() {<br />

int x = 0; atomic_int y = 0;<br />

{{{ { x = 1;<br />

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

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

||| { r1 = y.load(acquire);<br />

r2 = x; }<br />

}}}<br />

return 0;<br />

}<br />

c:W NA x=1rf<br />

f:R ACQ y=1<br />

sb sb<br />

d:W REL y=1 g:R NA x=1<br />

sb,rs rf<br />

e:W RLX y=1<br />

<strong>The</strong> default Power compilation of the two child threads is given below:<br />

stw 1,0(x) lwz r1,0(y)<br />

lwsync cmpw r1,r1<br />

stw 1,0(y) beq LC00<br />

stw 1,0(y) LC00:<br />

isync<br />

lwz r2,0(x)<br />

<strong>The</strong>re is an lwsync barrier above the first write to the atomic location. <strong>The</strong> lwsync<br />

barrier forces the write to x to be committed <strong>and</strong> propagated to the other thread before<br />

program-order-later writes, <strong>and</strong> therefore does not just order the first write to the atomic<br />

location; it serves to order the second write to the atomic location as well. <strong>The</strong> lwsync<br />

prevents the out-of-order commitment or propagation of the write of x <strong>and</strong> either write of<br />

y. <strong>The</strong>branch-control-isynconthesecondthreadinhibitsreadspeculation. Consequently,<br />

it is not possible to see MP relaxed behaviour in the program above. Both ARM <strong>and</strong>

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

Saved successfully!

Ooh no, something went wrong!