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 upstd::sync::mpsc::SharedSender #1299
Conversation
alexcrichton
added
the
T-libs
label
Sep 28, 2015
sfackler
reviewed
Sep 28, 2015
|
|
||
| ```rust | ||
| impl<T: Send> Sender<T> { | ||
| pub fn shared(self) -> SharedSender<T> { |
This comment has been minimized.
This comment has been minimized.
sfackler
Sep 28, 2015
Member
I would personally prefer this to a second channel constructor function, but discoverability might be hard?
This comment has been minimized.
This comment has been minimized.
seanmonstar
Sep 28, 2015
Author
Contributor
Er, I forgot to add description as to its downside: if you at the beginning you want a shared sender, this is just wasted operations going from oneshot -> shared, and bumping the internal counter by one since the Sender will be dropped and drop the counter.
This comment has been minimized.
This comment has been minimized.
|
I'm not terribly familiar with the internals of |
This comment has been minimized.
This comment has been minimized.
|
@BurntSushi a Reasons: |
This comment has been minimized.
This comment has been minimized.
|
I think that it's probably worth exploring adding |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton huh, I didn't consider that it'd be possible to detect concurrent access. I suppose with a |
This comment has been minimized.
This comment has been minimized.
|
Yeah I imagine something along those lines could be done. Some extra synchronization will have to happen no matter what (and it may be quite difficult to bolt on the already large amount going on), but in theory if concurrent access could be detected in a lightweight manner a CAS-like thing could be done to upgrade the channel, and the first thread to succeed ends up creating the new shared channel while all other threads fail the CAS and then start re-using the shared channel from the initial thread. Again, though, this implementation would be significantly more complicated than the outline you've got in this RFC. The benefit, however, are that we don't need another type of sender which would be nice! |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton it might be nice not having an additional |
eefriedman
referenced this pull request
Sep 29, 2015
Closed
Make SharedLayoutContext threadsafe. #7524
This comment has been minimized.
This comment has been minimized.
|
@seanmonstar Thanks for the explanation! That was helpful. Two more questions (again, please keep in mind that my familiarity with the
|
BurntSushi
self-assigned this
Sep 30, 2015
This comment has been minimized.
This comment has been minimized.
|
@BurntSushi I tried to make a couple queues with as few operations as possible, to make a benchmark. I can't say if the If sane, then this benchmark gave me these results on my crappy machine:
|
This comment has been minimized.
This comment has been minimized.
TyOverby
commented
Oct 6, 2015
|
I think that this will be really confusing for people because of the If you asked me which channel implements |
This comment has been minimized.
This comment has been minimized.
|
@TyOverby I agree that the naming of |
This comment has been minimized.
This comment has been minimized.
|
OK, so let me see if I've got the situation right. I think we have some variation of the following four choices:
Is there a choice I've left out? None of them look particularly appealing to me. I guess the next thing to look at are use cases for making channels |
This comment has been minimized.
This comment has been minimized.
|
The original motivation I had for writing this RFC was because it's a common stumbling block when people try to use hyper's Server. The Server takes a So the following situation happens a lot: let (tx, rx) = channel();
Server::http(addr).listen(move |req, res| {
tx.send("request!"); // tx does not implement Sync
});With the unfortunate solution being: let (tx, rx) = channel();
let tx = Mutex::new(tx);
Server::http(addr).listen(move |req, res| {
tx.lock().unwrap().send("request!");
}); |
This comment has been minimized.
This comment has been minimized.
|
I am personally pretty ambivalent here, and as such, I'm not sure exactly how to move it forward. Part of me thinks a tiny perf hit might be acceptable, especially if we get a more sane API, because wrapping channels in a mutex is a bummer. I will say though that @alexcrichton thinks this may be tricky to implement! |
This comment has been minimized.
This comment has been minimized.
|
Likewise, I don't strongly prefer either option over the other, I just want to stop wrapping senders in mutexs.
|
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
added
the
final-comment-period
label
Jan 29, 2016
This comment has been minimized.
This comment has been minimized.
tikue
commented
Feb 2, 2016
|
I ran into this issue the other day with a client that spins up a thread that I don't feel strongly about the particular implementation; any |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this during the triage meeting today and the decision was to close. This unfortunately doesn't interact well with code that already takes a Thanks for the RFC, though, @seanmonstar! |
seanmonstar commentedSep 28, 2015
Add a
SharedSendertostd::sync::mpscthat implementsSync.Rendered