Closed m-mueller678 closed 4 months ago
rayon::scope
runs its closure within the pool -- this is its main distinction versus in_place_scope
. Your playground even shows this by ThreadId numbers, where main is 1 and the pool (including the scope) run on 2 and 3. Your main thread is entirely blocked until it all finishes.
https://docs.rs/rayon/latest/rayon/fn.scope.html
The closure given to
scope()
executes in the Rayon thread-pool, as do those given tospawn()
.
https://docs.rs/rayon/latest/rayon/fn.in_place_scope.html
This is just like
scope()
except the closure runs on the same thread that callsin_place_scope()
. Only work that it spawns runs in the thread pool.
You are right, I must have misread the output from the playground. Confirmation bias, I guess. I missed the part about the closure being run in the thread pool and thought it would be like std
's.
Is there a way to prevent the main thread from participating in the global thread pool? It seems to be included even without calling
ThreadPoolBuilder::use_current_thread
?playround
In this example, one tasks runs at a time. When the sleep in scope completes, two tasks are run at a time, one on the main thread and one on an additional thread. I would expect that there are two threads in addition to the main thread. If this is intended behavior, I think the documentation around ThreadPoolBuilder should make this more clear.