pub struct CpuPool { /* private fields */ }Expand description
A persistent pool of parked workers.
Dropping the pool asks every worker to leave and joins it, so a pool
never outlives its threads. The process-wide pool is a static and
is therefore never dropped, exactly like rayon’s global pool.
Implementations§
Source§impl CpuPool
impl CpuPool
Sourcepub fn new(threads: usize) -> Self
pub fn new(threads: usize) -> Self
Spawn threads workers, minus the submitter: the thread that
calls Self::run is a worker too, which is why a one-thread
pool spawns nothing at all and still works.
Sourcepub fn num_threads(&self) -> usize
pub fn num_threads(&self) -> usize
Total width including the submitting thread.
Sourcepub fn run<F: Fn(usize) + Sync>(&self, n_tasks: usize, f: &F) -> bool
pub fn run<F: Fn(usize) + Sync>(&self, n_tasks: usize, f: &F) -> bool
Run f(task) for every task in 0..n_tasks.
Returns false without running anything if another thread is
already inside a region – the caller is expected to fall back to
rayon rather than serialize behind it. Returns true when the
work is complete, including the nested case, where the tasks run
inline on the calling thread.
A panic in f is re-raised here, on the submitting thread.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for CpuPool
impl !RefUnwindSafe for CpuPool
impl !UnwindSafe for CpuPool
impl Send for CpuPool
impl Sync for CpuPool
impl Unpin for CpuPool
impl UnsafeUnpin for CpuPool
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
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> ⓘ
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> ⓘ
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