Comments (5)
I don't think it is allowed to completely remove independent SC operations
LLVM certainly does not agree with your reasoning: this becomes a NOP.
pub fn test() {
let x = AtomicUsize::new(0);
x.load(Ordering::SeqCst);
}
Stores also get removed. I think they just didn't implement the pass that removes dead RMWs.
from event-listener.
The MSRV of the smol-rs
project previously did not allow for inline assembly. See smol-rs/smol#244. But now it does, so we should probably bump the MSRV so we can directly use the code that we want.
from event-listener.
Filed #71 to resolve this.
why doesn't this use inline assembly?
When this crate was first released, inline assembly was not stable. And for a long time after that, we used MSRV that older than 1.59.
Since we have recently raised the MSRV of some smol-rs crates to 1.63, I think this is an appropriate time to address this issue.
and the myth that no sane compiler is going to optimize atomics is a myth. However, I admit I don't know enough about this specific case to say whether this is a risk for this crate.
The C++20 memory model states that the SC operation "establish a single total modification order of all atomic operations that are so tagged". https://en.cppreference.com/w/cpp/atomic/memory_order#Sequentially-consistent_ordering
While it may be possible to "merge two atomic operations when there are only pure operations in the middle" as described in the article you linked to, I don't think it is allowed to completely remove independent SC operations (unless the compiler can prove that there are never any SC operations that could be synchronized with it by inspecting all programs). (It may be possible to replace SC CAS with SC fence or other SC RMW, but it doesn't lose the property we need here.)
So, unless the C++ memory model changes the property mentioned above in the future, I expect that no wrong code will be generated here, but inline assembly is the "definitely correct" choice here, and I agree that using inline assembly is definitely preferable.
from event-listener.
The MSRV of the
smol-rs
project previously did not allow for inline assembly. See smol-rs/smol#244. But now it does, so we should probably bump the MSRV so we can directly use the code that we want.
Ah, if it's just an MSRV issue that is great! And thanks @taiki-e for getting the ball rolling with that PR. :)
If the lock cmpxchg
can be faster than mfence
it might also be worth trying to get LLVM to generate the former instead of the latter for SC fences -- then all code would benefit.
The C++20 memory model states that the SC operation "establish a single total modification order of all atomic operations that are so tagged". https://en.cppreference.com/w/cpp/atomic/memory_order#Sequentially-consistent_ordering
Yeah, but the way that order interacts with the other orders isn't always entirely how one would expect, I think... so it's certainly not obvious to me that compilers are not allowed to drop the access. In particular this order AFAIK does not participate when determining synchronizes-with edges -- but an SC fence has the effects of a release-acquire fence and can hence establish synchronizes-with edges.
You have to study the formalizations of this model, I don't think the English prose can be precise enough for subtle questions like this.
from event-listener.
Oh, that is interesting. I can reproduce it, even with a very old rustc, even if I used compiler_fence around SC load/store. https://godbolt.org/z/xsvG5Ke58
from event-listener.
Related Issues (20)
- Unsoundness HOT 11
- RFC: Less complex, footgun free API HOT 2
- expose listener count HOT 4
- Remove concurrent-queue dependency
- `NonBlocking` doesn't implement `Send` and `Sync` HOT 2
- Possible racecondition HOT 1
- Question about new API HOT 3
- Miri reports a deadlock in `async-lock` HOT 2
- Upgrading v4 to v5 panic: Listener was never inserted into the list HOT 6
- During racy initialization, a race can happen where a notification is dropped HOT 2
- Is `Event::notify(usize::MAX)` signal safe? HOT 4
- Loosen concurrent-queue dependency HOT 2
- This seems actually not stable(Dead lock) HOT 5
- fmt::Debug should produce actually useful output
- Split event-listener-strategy out into a new crate HOT 2
- Miri test failure with --no-default-features HOT 1
- EventListener::new footgun HOT 1
- Remove EventListener::new footgun HOT 6
- `EventListener` doesn't implement `UnwindSafe` HOT 1
- wasm test failed with "index out of bounds: the len is 0 but the index is 4" HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from event-listener.