-
Notifications
You must be signed in to change notification settings - Fork 7
Use of volatile read is unsound #2
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
Comments
That's not what your quote says. It just says that the operations aren't properly atomic, which means that they may be split into multiple operations, which would not be atomic (i.e. you could observe a mix of the new and old value). Also volatile operations don't have any of the memory ordering properties that atomic operations have. We don't actually need either of these properties in seqlock:
In practice, using volatile to read concurrently modified data is fine, and the Linux kernel even relies on this for their |
So I get where you're coming from on that interpretation. I'm honestly a bit surprised because when I was looking at the spec to find the relevant quote, I could've sworn seeing a stronger wording in the past (explicitly calling out using volatile on concurrently-modified memory as UB). It's possible I'm just making that up. In any case, it strikes me that a) the spec definitely isn't precisely worded enough to guarantee that this isn't technically UB, but also that b) your point about the fact that people rely on this behavior is a fair one. In any case, I came here from rust-lang/rust#59155 (comment), so hopefully that will obsolete this anyway. Cheers! |
The volatile read at https://github.com/Amanieu/seqlock/blob/master/src/lib.rs#L147 is unsound - according to the LLVM memory model, volatile reads on data which is being concurrently modified are UB:
- https://llvm.org/docs/Atomics.html
This should be a relaxed atomic load instead.
The text was updated successfully, but these errors were encountered: