Reputation: 3209
Given is the following function foo
int x;
void foo()
{
[...]
x = 0x1234;
cv.set();
[...]
}
cv
is a non-standard condition variable, offered by an external API I have to use. Which guarantees does the C++ standard give, so I can be sure, that x
is never written after the condition variable is set.
The condition variable of course uses a memory fence internally, but since due to the implementation being in a different translation unit, the compiler can't know that during the compilation of foo.
Upvotes: 0
Views: 79
Reputation: 473447
cv
is a non-standard condition variable ... Which guarantees does the C++ standard
None. The standard cannot guarantee the behavior of something that by definition is outside of the standard's purview. If cv
does not (internally) use things the C++ standard recognizes, then the standard cannot talk about their behavior.
You therefore only have the guarantees that the maker of cv
gives you, as well as those of your implementation.
That being said:
since due to the implementation being in a different translation unit, the compiler can't know that during the compilation of foo.
If the compiler can't see the implementation of some function, how would the compiler know if it is using a C++ condition_variable
or a POSIX thing or something else? Or even none of those.
It can't. The compiler can't know that some function call won't invoke some standard-defined synchronization mechanism, so the implementation will have to assume that it does and avoid reordering instructions in a way that might violate such a mechanism.
Upvotes: 2