Sunday, 25 August 2013

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

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

In this answer, bdonlan states that code similar to the following:
int t;
volatile int a, b;
t = x;
a = t;
b = t;
may be transformed by the compiler into:
a = x;
b = x;
My question is, is this still allowed if x is an atomic variable with
relaxed loads, as in the following?
atomic<int> x;
int t;
volatile int a, b;
t = x.load(std::memory_order_relaxed);
a = t;
b = t;
assert(a == b); // Will this hold?
As the title says, are C++11 compilers allowed to introduce additional
loads of atomic variables? What about additional stores?

No comments:

Post a Comment