Skip to content

Get the global thread pool repeatedly (to pass to a function) #909

@kno10

Description

@kno10

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions