Quantcast
Viewing latest article 23
Browse Latest Browse All 60

Understanding sequential consistency fence in C++

I was reading about memory orders in C++. I could understand relaxed and acquire-release models a well. But I'm struggling with sequential-consistency.

If I am not wrong, from cppreference, std::memory_order_seq_cst'operation' is equivalent to:

  • an acquire operation plus a single total order when the operation is 'load'.
  • a release operation plus a single total order when the operation is 'store'.
  • an acq-rel operation plus a single total order when the operation is 'read-modify-write'.

But what is the case with std::memory_order_seq_cst'fence'? Is it equivalent to which of these?

  • an acquire fence plus a single total order.
  • a release fence plus a single total order.
  • an acq-rel fence plus a single total order.

If it is equivalent to one of above, what about the other two?

As far as I know, if it is case 1 (acquire fence), compilers would be free to move any write operation from above the fence to below it. Similarly, if it is case 2 (release fence), compilers would be free to move any read operation from below the fence to above it. Finally, if it is case 3 (acq-rel fence), compilers would be disallowed to move any instructions across the fence. Is this correct?

I'm still in a lot of confusion. Above statements may be incorrect. Please correct me where I'm wrong.


Viewing latest article 23
Browse Latest Browse All 60

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>