Is there any compiler barrier which is equal to asm("" ::: "memory") in C++11?
<p>My test code is as below, and I found that only the <code>memory_order_seq_cst</code> forbade compiler's reorder.</p>

<pre><code>#include &lt;atomic&gt;

using namespace std;

int A, B = 1;

void func(void) {
    A = B + 1;
    atomic_thread_fence(memory_order_seq_cst);
    B = 0;
}
</code></pre>

<p>And other choices such as <code>memory_order_release</code>, <code>memory_order_acq_rel</code> did not generate any compiler barrier at all.</p>

<p>I think they must work with atomic variable just as below.</p>

<pre><code>#include &lt;atomic&gt;

using namespace std;

atomic&lt;int&gt; A(0);
int B = 1;

void func(void) {
    A.store(B+1, memory_order_release);
    B = 0;
}
</code></pre>

<p>But I do not want to use atomic variable. At the same time, I think the "asm("":::"memory")" is too low level.</p>

<p>Is there any better choice?</p>