-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document some places where crossbeam tests the limits of the C++ memory model -- or crosses them #234
Conversation
Thank you! Now that I think of it, there should probably go an |
TBH I have no idea, I don't nearly know enough about this code to answer your question.^^ But my reading of the comment (above the stuff I added) is that this fence is deliberately not added because in x86 assembly, it is not needed, but the compiler is not smart enough to optimize this correctly. Of course that doesn't mean the compiler won't do something stupid here, but unfortunately SC accesses (mixed with other accesses to the same location) are amongst the least understood parts of the C++ concurrency model... Let's see what @jeehoonkang has to say. |
Yeah, I think the motivation here is avoiding To summarize my stance, there are two hacks in play:
@RalfJung I just realized this point. Sorry to have you work twice, but if you agree with my explanation, would you please document it as a comment? |
The first part isn't a hack though, is it? It is quite clear from the x86/TSO model that a CAS has the effect of a fence. So the only hack here is to pretend we are working in assembly while we are not -- to rely on how CAS is codegen'd, and to hope that either this is correct in the C++ model as well or else LLVM does not notice what we are doing here. |
Exactly - we'd ideally use inline assembly here but can't on stable Rust. The CAS will compile into the desired I think it'd be a good idea to put a compiler fence after the CAS so that it becomes a real fence from the processor's standpoint and from the compiler's standpoint. |
I extended the comment to mention inline assembly. Do we have compiler fences on stable Rust...? |
We do, since 1.21: https://doc.rust-lang.org/std/sync/atomic/fn.compiler_fence.html |
I added a compiler fence after the CAS. |
@RalfJung I like how precise and cautious your comments are :) bors r+ |
234: Document some places where crossbeam tests the limits of the C++ memory model -- or crosses them r=stjepang a=RalfJung Thanks to @jeehoonkang for some early feedback. Co-authored-by: Ralf Jung <[email protected]>
Build succeeded |
Thanks to @jeehoonkang for some early feedback.