Struct rayon_core::ThreadPool
[−]
[src]
pub struct ThreadPool { /* fields omitted */ }
Methods
impl ThreadPool
[src]
fn new(configuration: Configuration) -> Result<ThreadPool, Box<Error>>
Constructs a new thread pool with the given configuration. If
the configuration is not valid, returns a suitable Err
result. See InitError
for more details.
fn install<OP, R>(&self, op: OP) -> R where OP: FnOnce() -> R + Send
Executes op
within the threadpool. Any attempts to use
join
, scope
, or parallel iterators will then operate
within that threadpool.
Warning: thread-local data
Because op
is executing within the Rayon thread-pool,
thread-local data from the current thread will not be
accessible.
Panics
If op
should panic, that panic will be propagated.
fn current_num_threads(&self) -> usize
Returns the (current) number of threads in the thread pool.
Future compatibility note
Note that unless this thread-pool was created with a
configuration that specifies the number of threads, then this
number may vary over time in future versions (see the
num_threads()
method for details).
fn current_thread_index(&self) -> Option<usize>
If called from a Rayon worker thread in this thread-pool,
returns the index of that thread; if not called from a Rayon
thread, or called from a Rayon thread that belongs to a
different thread-pool, returns None
.
The index for a given thread will not change over the thread's lifetime. However, multiple threads may share the same index if they are in distinct thread-pools.
Future compatibility note
Currently, every thread-pool (including the global
thread-pool) has a fixed number of threads, but this may
change in future Rayon versions (see the num_threads()
method
for details). In that case, the index for a
thread would not change during its lifetime, but thread
indices may wind up being reused if threads are terminated and
restarted.