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 upExtend atomic compare_and_swap #1443
Conversation
nrc
added
the
T-libs
label
Jan 5, 2016
Amanieu
referenced this pull request
Jan 17, 2016
Merged
Implement compare_exchange and compare_exchange_weak #30969
alexcrichton
self-assigned this
Jan 21, 2016
This comment has been minimized.
This comment has been minimized.
|
For some history, we currently auto-calculate the second ordering when emitting an LLVM instruction for this, which was added in rust-lang/rust@30ff17f when upgrading LLVM and it happened to start requiring two orderings. I don't believe we ever revisited that this until just now! Also for reference, the LLVM documentation for the Alright, so with all that out of the way, here are some thoughts of mine:
pub trait IntoTwoOrderings {
pub fn into_two_orderings(self) -> (Ordering, Ordering);
}
impl IntoTwoOrderings for Ordering {
pub fn into_two_orderings(self) -> (Ordering, Ordering) { (self, self) }
}
impl IntoTwoOrderings for (Ordering, Ordering) {
pub fn into_two_orderings(self) -> (Ordering, Ordering) { self }
}
pub fn compare_and_swap<O: IntoTwoOrderings>(&self, expected: T, ordering: O) -> T;Alright, now with all that out of the way, my personal opinion is that we should stick with this RFC basically as-is. I think that there's utility in keeping the one-ordering methods as they're somewhat easier to understand, and adding lots of methods won't really hurt the types. That being said I'm not super certain about one alternative over the other, I'm just swaying a bit in that direction. |
This comment has been minimized.
This comment has been minimized.
|
I don't think adding hacks to extend the I disagree that a single I'm actually starting to prefer the idea of simply deprecating |
This comment has been minimized.
This comment has been minimized.
|
In C++ though it looks like you've at least got the option of not specifying a second ordering? (I may be misunderstanding overloading...) If it's idiomatic in C++, however, to always have two orderings then I'd be pretty ok pushing on deprecation + new names for the new functions |
This comment has been minimized.
This comment has been minimized.
That is correct, C++ gives you 3 options: no ordering (defaults to
To be precise, in C++ it is idiomatic to either specify both orderings or none at all. But I've never really seen any code that just specifies a single ordering. If you look at C11, it only provides forms that accept no orderings or both. I've updated the RFC to propose deprecating |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the update! This is looking pretty good to me. I might slightly prefer |
This comment has been minimized.
This comment has been minimized.
|
Note that this is deprecating the My own personal opinion here is that I would prefer the name |
alexcrichton
added
the
final-comment-period
label
Feb 11, 2016
This comment has been minimized.
This comment has been minimized.
Same here. |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Feb 13, 2016
|
Please use the ISO C11 and/or ISO C++ names and semantics whenever possible. Otherwise, it would be a complete mess to understand code where more than one language (Rust, C, C++) is being used to modify the same value using atomic primitives. The ISO C and C++ stuff isn't perfect, but people are working hard to get them to be closer to perfect and there's no need to reinvent the wheel or to generate confusion with different names or slightly different semantics for similarly-named things. |
This comment has been minimized.
This comment has been minimized.
I do not find this argument persuading. For the weak CAS, I’d rather use java style naming (appending/prepending |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Feb 14, 2016
C11 uses the same names as C++11 for these, except they prefixed |
This comment has been minimized.
This comment has been minimized.
|
I would prefer atomic_compare_exchange_strong for consistency with C++, but I don't feel too strongly either way. |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this RFC during triage yesterday and the conclusion was that we'd like to merge! We felt, however, that the name |
This comment has been minimized.
This comment has been minimized.
|
Done |
Amanieu commentedJan 5, 2016
Rendered