Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd extra access methods for atomic types #1649
Conversation
This comment has been minimized.
This comment has been minimized.
|
All the other methods for loading the values of atomic types take an argument to specify the ordering. Why not these? |
This comment has been minimized.
This comment has been minimized.
|
What is required for code to be sound while calling the unsafe |
This comment has been minimized.
This comment has been minimized.
Because they are accessing the value non-atomically.
The pointer needs to be valid, and you need to make sure that the other thread is not accessing the integer non-atomically while you are performing atomic operations on it. The reason a raw pointer is used here is because the value is a shared and mutable integer, which can't be expressed using a reference. |
alexcrichton
added
the
T-libs
label
Jun 20, 2016
This comment has been minimized.
This comment has been minimized.
|
The |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton I think simply documenting that |
This comment has been minimized.
This comment has been minimized.
|
Aren't there platforms where we'd have to use AtomicUsize to emulate smaller atomics? |
This comment has been minimized.
This comment has been minimized.
|
@Amanieu yeah I might prefer to go that route (a function from @ubsan yeah but |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton ah, 'k. |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Hmm wouldn't that misbehave if you have like |
This comment has been minimized.
This comment has been minimized.
|
@glaebhoerl It isn't a problem since a modification to one |
aturon
self-assigned this
Jul 18, 2016
This comment has been minimized.
This comment has been minimized.
|
OK, after giving this RFC some though, I'm in favor of the general idea. In particular, I've wanted something like I personally would prefer to start with just |
This comment has been minimized.
This comment has been minimized.
|
@aturon The reason for adding into_inner was to be able to consume an atomic that wasn't declared with a mutable binding. In practice I expect 99% of uses of |
aturon
added
the
I-nominated
label
Jul 25, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team is leaning towards merging this as is (with |
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Jul 26, 2016
alexcrichton
referenced this pull request
Aug 11, 2016
Closed
Tracking issue for Atomic*::{get_mut, into_inner} #35603
This comment has been minimized.
This comment has been minimized.
|
Discussed during libs triage the other day, the conclusion was to merge Thanks again for the RFC @Amanieu! |
alexcrichton
merged commit c445f53
into
rust-lang:master
Aug 11, 2016
bors
added a commit
to rust-lang/rust
that referenced
this pull request
Aug 19, 2016
This comment has been minimized.
This comment has been minimized.
willmo
commented
Sep 13, 2016
|
I still get an improper_ctypes warning when I try to use an atomic for FFI. Is this expected? (Relative Rust noob here; apologies if this is a dumb question or an inappropriate place/way to comment.) |
This comment has been minimized.
This comment has been minimized.
|
What this RFC is proposing is ability to extract plain |
This comment has been minimized.
This comment has been minimized.
|
Actually, it has already been implemented: rust-lang/rust#35719 |
This comment has been minimized.
This comment has been minimized.
willmo
commented
Sep 18, 2016
•
|
@nagisa, it seems to me that with this RFC the layout of
But the compiler has no way of knowing this. Apologies that this wasn't clear from my earlier example, but as in the example of Linux futexes, I need to have Rust atomically manipulate a value shared with C. So it seems like the correct solution is a pointer cast, and the effect of this RFC is that this is now defined/correct? (That's another contrived example, but closer to what I need to do.) But this is not nearly as nice as being able to use I can't even use |
This comment has been minimized.
This comment has been minimized.
|
My opinion is that structs with only a single member should be defined as having the same representation as that element. As a workaround, I guess we could just mark the atomic types as |
Amanieu commentedJun 15, 2016
This RFC adds the following methods to atomic types:
get_mutinto_inneras_rawfrom_rawRendered