Assume I am writing a library with a function
fn lots_of_work(&pool: ThreadPool) {
pool.scope(|s| { s.spawn( ... ); })
}
where the responsibility of configuring and selecting the thread pool is delegated to the caller.
The user can use the global thread pool via
let pool = rayon::ThreadPoolBuilder::new().build_global().unwrap();
lots_of_work(&pool)
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
lots_of_work(rayon::get_global_threadpool())
where the user does not need to track his reference to the global pool forever.
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.