[−][src]Struct rustc_rayon::ThreadPool
Represents a user created thread-pool.
Use a ThreadPoolBuilder
to specify the number and/or names of threads
in the pool. After calling ThreadPoolBuilder::build()
, you can then
execute functions explicitly within this ThreadPool
using
ThreadPool::install()
. By contrast, top level rayon functions
(like join()
) will execute implicitly within the current thread-pool.
Creating a ThreadPool
let pool = rayon::ThreadPoolBuilder::new().num_threads(8).build().unwrap();
install()
executes a closure in one of the ThreadPool
's
threads. In addition, any other rayon operations called inside of install()
will also
execute in the context of the ThreadPool
.
When the ThreadPool
is dropped, that's a signal for the threads it manages to terminate,
they will complete executing any remaining work that you have spawned, and automatically
terminate.
Methods
impl ThreadPool
[src][−]
pub fn new(
configuration: Configuration
) -> Result<ThreadPool, Box<dyn Error + 'static>>
[src][+]
configuration: Configuration
) -> Result<ThreadPool, Box<dyn Error + 'static>>
Use ThreadPoolBuilder::build
pub fn scoped_pool<F, R, H>(
builder: ThreadPoolBuilder,
main_handler: H,
with_pool: F
) -> Result<R, ThreadPoolBuildError> where
F: FnOnce(&ThreadPool) -> R,
H: Fn(&mut dyn FnMut()) + Send + Sync,
[src][+]
builder: ThreadPoolBuilder,
main_handler: H,
with_pool: F
) -> Result<R, ThreadPoolBuildError> where
F: FnOnce(&ThreadPool) -> R,
H: Fn(&mut dyn FnMut()) + Send + Sync,
pub fn install<OP, R>(&self, op: OP) -> R where
OP: FnOnce() -> R + Send,
R: Send,
[src][+]
OP: FnOnce() -> R + Send,
R: Send,
pub fn current_num_threads(&self) -> usize
[src][+]
pub fn current_thread_index(&self) -> Option<usize>
[src][+]
pub fn current_thread_has_pending_tasks(&self) -> Option<bool>
[src][+]
pub fn join<A, B, RA, RB>(&self, oper_a: A, oper_b: B) -> (RA, RB) where
A: FnOnce() -> RA + Send,
B: FnOnce() -> RB + Send,
RA: Send,
RB: Send,
[src][+]
A: FnOnce() -> RA + Send,
B: FnOnce() -> RB + Send,
RA: Send,
RB: Send,
pub fn scope<'scope, OP, R>(&self, op: OP) -> R where
OP: for<'s> FnOnce(&'s Scope<'scope>) -> R + 'scope + Send,
R: Send,
[src][+]
OP: for<'s> FnOnce(&'s Scope<'scope>) -> R + 'scope + Send,
R: Send,
pub fn spawn<OP>(&self, op: OP) where
OP: FnOnce() + Send + 'static,
[src][+]
OP: FnOnce() + Send + 'static,
Trait Implementations
impl Drop for ThreadPool
[src][+]
impl Debug for ThreadPool
[src][+]
Auto Trait Implementations
impl Send for ThreadPool
impl Sync for ThreadPool
Blanket Implementations
impl<T> From for T
[src][+]
impl<T, U> Into for T where
U: From<T>,
[src][+]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T> Borrow for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,
impl<T> Any for T where
T: 'static + ?Sized,
[src][+]
T: 'static + ?Sized,