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.

c;isync Memory Barrier for Load Acquire<br />

By <strong>in</strong>sert<strong>in</strong>g a conditional branch, bc, before <strong>the</strong> isync both <strong>the</strong><br />

isync and stw become speculative until <strong>the</strong> branch outcome is known.<br />

We can use beq as follows:<br />

ldw r1,r2,r3 # r1 = MEMORY[r2+r3]<br />

cmp. r1,r1 # certa<strong>in</strong>ly true but <strong>the</strong> beq must<br />

beq # wait accord<strong>in</strong>g to <strong>the</strong> specification<br />

isync # s<strong>in</strong>ce no speculative stw is allowed.<br />

stw r4,r5,r6<br />

S<strong>in</strong>ce <strong>the</strong> store may not execute speculatively it must wait for <strong>the</strong><br />

branch outcome.<br />

This memory barrier is <strong>the</strong> fastest.<br />

The previous two, however, can order <strong>in</strong>structions <strong>from</strong> different<br />

processors due to <strong>the</strong> hwsync/lwsync are cumulative — see below.<br />

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

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

Saved successfully!

Ooh no, something went wrong!