pub struct ThreadPool { /* private fields */ }Expand description
A scoped thread pool wrapper around rayon::ThreadPool.
Unlike the global pool, a ThreadPool can be created and destroyed
independently, which is useful for short-lived parallel tasks or tests.
§Example
use ocas_core::thread_pool::ThreadPool;
let pool = ThreadPool::new(2).expect("failed to create pool");
let result = pool.install(|| {
let (a, b) = rayon::join(|| 1 + 2, || 3 + 4);
a + b
});
assert_eq!(result, 10);Implementations§
Source§impl ThreadPool
impl ThreadPool
Sourcepub fn new(threads: usize) -> Result<Self>
pub fn new(threads: usize) -> Result<Self>
Create a new thread pool with the given number of worker threads.
§Errors
Returns OcasError::BackendError if rayon fails to build the pool
(for example, because the global pool was already initialized with a
different configuration).
Sourcepub fn current_num_threads(&self) -> usize
pub fn current_num_threads(&self) -> usize
Return the number of worker threads in this pool.
Auto Trait Implementations§
impl !RefUnwindSafe for ThreadPool
impl !UnwindSafe for ThreadPool
impl Freeze for ThreadPool
impl Send for ThreadPool
impl Sync for ThreadPool
impl Unpin for ThreadPool
impl UnsafeUnpin for ThreadPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more