Re: What in C++11 prohibits mutex operations from being reordered?
On Friday, April 5, 2013 3:41:56 AM UTC+1, Michael Podolsky wrote:
On Apr 4, 12:04 pm, James Kanze <james.ka...@gmail.com> wrote:
On the other hand, I've never heard of a compiler capable of
proving much of anything involving mutexes, and especially not
that changing their order doesn't affect observable behavior
(especially as it usually does).
Why affecting observable behavior is problematic?
"An instance of the abstract machine can thus have more than one
possible execution for a given program and a given input."
1.9p3
Because the expression is a short-hand for "changing observable
behavior in a way that results in behavior which is not in the
set of possible behaviors, as defined by the standard." It's
certain that in an expression like f() + g(), where both f() and
g() contain observable behavior, the compiler can change the
order of these observable behaviors depending on the level of
optimization. On the other hand, it cannot interleave the
functions in a way that would introduce undefined behavior
(which is not present in the original code). It can only
interleave execution to the extent that is can prove that the
resulting behavior corresponds to a possible behavior without
the interleaving.
--
James