-
Notifications
You must be signed in to change notification settings - Fork 484
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
On utilizing current thread with ThreadPool #930
Comments
Huh, that's pretty clever! I will caution one caveat that the current thread must not be a part of a pool already, or else
I generally wouldn't worry about that though -- it should sleep with no overhead, apart from the memory use of the thread stack. Is there something that makes this more of a concern for you?
That's a requirement of |
Yeah, exactly. The real example actually utilizes an external pool (i.e just sends Wouldn't it be possible to link newly created |
How would you do that, when there is no lifetime parameter on Note that the problem is not really about keeping the pool alive, but rather how to ensure that it executes the The |
Yeah, I was thinking about API similar to Moreover I'm not sure it's even possible to get it around for a generic case (i.e |
I'd like to utilize current thread while using a
ThreadPool
, how shall I do that? Consider this example:This code will block main thread until
do_some_work
is completed. But the problem is that the execution is performed in newly created pool without utilizing current running thread (it just waits for result).One may think about overriding
spawn_handler
with using the current thread instead of first thread spawn:Which is great and works for
do_some_work: 'static
&&do_some_work::Output: 'static
. But these are actually redundant requirements for this particular case (i.edo_some_work
overlivesThreadPool
).Probably related:
rayon::spawn
have completed #650The text was updated successfully, but these errors were encountered: