-
Notifications
You must be signed in to change notification settings - Fork 517
Get the global thread pool repeatedly (to pass to a function) #909
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
Comments
This doesn't work even once, because One thing you can do right now is make the pool argument optional: fn lots_of_work(pool: Option<&ThreadPool>) {
if let Some(pool) = opt_pool {
pool.scope(|s| do_scoped_work(s))
} else {
rayon::scope(|s| do_scoped_work(s))
}
} However, a caveat is that See also #841 proposing to expose the current pool handle, and we could possibly do similar for the explicit global pool. |
Does this mean that if the user did pool.scope(|s| do_scoped_work())
fn do_scoped_work() {
rayon::scope(|s| ...)
} then |
Correct, |
The user can also call |
Maybe this could be clarified in the documentation. |
Hmm, I think the point Documentation improvements are always welcome! |
I am using a library that is using rayon. I want to initialize the threadpool in a specific way (e.g. number of threads), and I want to do this as late as possible to incur overhead only when we need the threads. However, when I initialize it too late the threadpool might be initialized by code of a dependency. I figured it would be nicer if I could pass an explicit thread pool to use to dependencies (or use Would it be possible to have function as OP suggested: rayon::get_global_threadpool() At least we could be explicit about it then! |
Assume I am writing a library with a function
where the responsibility of configuring and selecting the thread pool is delegated to the caller.
The user can use the global thread pool via
but this can only be called once, because
build_global()
fails if used a second time.But I do not want the user to have to create a new thread pool every time, either.
What is the best way to allow the user to call the function with the default thread pool?
I could not find something like
where the user does not need to track his reference to the global pool forever.
The text was updated successfully, but these errors were encountered: