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 upVariant on `join` that does not send closure `A`? #20
Comments
This comment has been minimized.
This comment has been minimized.
|
First thing in |
This comment has been minimized.
This comment has been minimized.
|
@cuviper ah, true. Good point. |
This comment has been minimized.
This comment has been minimized.
|
Meh. Not worth it, I don't think. |
nikomatsakis
closed this
Jan 28, 2016
nikomatsakis
reopened this
Jan 31, 2016
nikomatsakis
added
enhancement
question
labels
Jan 31, 2016
nikomatsakis
changed the title
closure A in `join` does not need to be send
Variant on `join` that does not send closure `A`
Jan 31, 2016
nikomatsakis
changed the title
Variant on `join` that does not send closure `A`
Variant on `join` that does not send closure `A`?
Jan 31, 2016
This comment has been minimized.
This comment has been minimized.
|
OK, I decided to reopen, but changed the title. It seems like there might be some use for this. The idea would be that sometimes you want to do work on the "main" thread while also doing parallel processing in parallel. Use case is the SDL-based visualizer in the nbody demo, where it'd be nice to assemble the frame in parallel with computing the next one. You can certainly do this with Rayon's existing join, but I think one is only supposed to do certain tasks from the "main" thread. Another use case would be anything that requires thread-local data. But I agree with @cuviper that this seems to be a distinct thing from the simple join, so maybe it would require a separate function. Or maybe we can rework join so that it's fine there. I don't know, but I'm going to leave it open as something to think about as a future enhancement. |
This comment has been minimized.
This comment has been minimized.
|
Maybe you just need something like a "future" for a single closure? Inject
the job and return the `Latch` (possibly wrapped) to let you wait for it
later.
|
This comment has been minimized.
This comment has been minimized.
|
@cuviper yes, but it would need a join scope of some kind in order to access borrowed data. So basically you could imagine adding an API like: join_scope(|scope| {
scope.fork(|| ...); // can call as many times as you want
});
// forked things are done nowBehind the scenes, this would need some sort of |
This comment has been minimized.
This comment has been minimized.
|
I think I'm just going to close this. It might be handy, but ... meh. We have scope now and I think concerning ourselves with |
nikomatsakis commentedJan 22, 2016
Since we are guaranteed to execute closure A on the main thread, it occurs to me that it does not really need to be
Send. Lifting this restriction would add a bit of flexibility. For example, one could thread some non-thread-safe data through the first closure, spawning tasks with the right closure. (Though you'd still have to write tasks in a kind of recursive style.)UPDATE: This doesn't quite work, but see this comment.