-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Implement Sync
for mpsc::Sender
#111087
Implement Sync
for mpsc::Sender
#111087
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
@rustbot label -T-libs |
This comment has been minimized.
This comment has been minimized.
This PR makes @rfcbot fcp merge |
Team member @BurntSushi has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Are we certain that the original reason for a @rfcbot concern why-not-sync |
Right now there are some failing tests. We should check to make sure those themselves don't raise any other concerns. @rfcbot concern failing-tests |
I dug up #11111 - which made senders (and other channel types)
I doubt that the decision was considered in-depth - my guess is that it was done just to keep options open for future implementation changes. But maybe @alexcrichton remembers ;) |
Ah, I found #42397 as well which made |
This isn't the right PR. Is it #93563? |
I guess the big question is why implement let (tx, rx) = std::sync::mpsc::channel();
// std::thread::scope(|s| {
// let tx1 = tx.clone();
// s.spawn(move || {
// tx1.send(1);
// });
//
// let tx2 = tx.clone();
// s.spawn(move || {
// tx2.send(2);
// });
// })
std::thread::scope(|s| {
s.spawn(|| {
tx.send(1);
});
s.spawn(|| {
tx.send(2);
});
}) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@rfcbot resolve failing-tests |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
@bors r+ |
cc @thomcc because they expressed thoughts on this. |
My thoughts (I'm assuming you're referring to this tweet) are just that it's a useful optimization sometimes to be able to do things like that (even the lower-complexity version where we just check an Arc's reference count somewhere). If we don't want to do it in the future, then IMO there's no harm in accepting this. My tweet was definitely not about this stabilization in particular -- which I'm not opposed to (std should be willing to prioritize ergonomics over having the best possible implementation1, as the best possible implementation for a given situation will almost always depend on that situation's specifics anyway) Footnotes
|
…mpiler-errors Rollup of 8 pull requests Successful merges: - rust-lang#111087 (Implement `Sync` for `mpsc::Sender`) - rust-lang#112763 (Bump compiler_builtins) - rust-lang#112963 (Stop bubbling out hidden types from the eval obligation queries) - rust-lang#112965 (Don't emit same goal as input during `wf::unnormalized_obligations`) - rust-lang#112973 (Make sure to include default en-US ftl resources for `rustc_error` crate) - rust-lang#112981 (Fix return type notation errors with -Zlower-impl-trait-in-trait-to-assoc-ty) - rust-lang#112983 (Fix return type notation associated type suggestion when -Zlower-impl-trait-in-trait-to-assoc-ty) - rust-lang#112986 (Update cargo) r? `@ghost` `@rustbot` modify labels: rollup
mpsc::Sender
is currently!Sync
because the previous implementation contained an optimization where the channel started out as single-producer and was dynamically upgraded on the first clone, which relied on a unique reference to the sender. This optimization is one of the main reasons the old implementation was so complex and was removed in #93563.mpsc::Sender
can now soundly implementSync
.Note for any potential confusion, this chance does not add MPMC behavior. This only affects the already
Send + Clone
sender, not receiver.It's technically possible to rely on the
!Sync
behavior in the same way as aPhantomData<*mut T>
, but that seems very unlikely in practice. Either way, this change is insta-stable and needs an FCP.@rustbot label +T-libs-api -T-libs