compiler_fence example is misleading #133014
Labels
A-atomic
Area: Atomics, barriers, and sync primitives
A-concurrency
Area: Concurrency
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
T-opsem
Relevant to the opsem team
Location
https://doc.rust-lang.org/nightly/core/sync/atomic/fn.compiler_fence.html#examples
Summary
This example makes it look like there is some kind of guarantee for a release fence that isn't paired with an acquire operation or fence, which as far as I can tell, is not the case. (See the C++ docs for regular (thread) fences that do not guarantee anything for an unpaired release fence and compiler (signal) fences that are described as strictly weaker than thread fences.)
So in this example there is no happens-before relation between the store of
IMPORTANT_VARIABLE
in main and the load thereof in the signal handler and therefore the signal handler may actually observeIS_READY == true
andIMPORTANT_VARIABLE == 0
.Presumably the example should have a load fence in the signal handler and explain in the prose text above that the loads can be reordered, too:
related: #129189
The text was updated successfully, but these errors were encountered: