multithreading - Are C++11 compilers allowed to introduce additional loads of atomic variables? -


in this answer, bdonlan states code similar following:

int t; volatile int a, b;  t = x; = t; b = t; 

may transformed compiler into:

a = x; b = x; 

my question is, still allowed if x atomic variable relaxed loads, in following?

atomic<int> x;  int t; volatile int a, b;  t = x.load(std::memory_order_relaxed); = t; b = t; assert(a == b);    // hold? 

as title says, c++11 compilers allowed introduce additional loads of atomic variables? additional stores?

the compiler allowed under as-if rule, load same memory location twice, compiler have show no other thread accessing same variable. either way, guaranteed a==b in example.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -