pub struct WorkerPool { /* private fields */ }rayon only.Expand description
A rayon thread pool with per-thread Worker state.
Each thread in the pool has its own Worker that can hold arbitrary state via
Worker::init. The state is thread-local and accessible during install
calls.
The pool supports multiple init/clear cycles, allowing reuse of the same threads with different state configurations.
Implementations§
Source§impl WorkerPool
impl WorkerPool
Sourcepub fn new(num_threads: usize) -> Result<Self, ThreadPoolBuildError>
pub fn new(num_threads: usize) -> Result<Self, ThreadPoolBuildError>
Creates a new WorkerPool with the given number of threads.
Sourcepub fn from_builder(
builder: ThreadPoolBuilder,
) -> Result<Self, ThreadPoolBuildError>
pub fn from_builder( builder: ThreadPoolBuilder, ) -> Result<Self, ThreadPoolBuildError>
Creates a new WorkerPool from a [rayon::ThreadPoolBuilder].
Sourcepub fn current_num_threads(&self) -> usize
pub fn current_num_threads(&self) -> usize
Returns the total number of threads in the underlying rayon pool.
Sourcepub fn init<T: 'static>(&self, f: impl Fn(Option<&mut T>) -> T + Sync)
pub fn init<T: 'static>(&self, f: impl Fn(Option<&mut T>) -> T + Sync)
Initializes per-thread Worker state on every thread in the pool.
Sourcepub fn broadcast(&self, num_threads: usize, f: impl Fn(&mut Worker) + Sync)
pub fn broadcast(&self, num_threads: usize, f: impl Fn(&mut Worker) + Sync)
Runs a closure on num_threads threads in the pool, giving mutable access to each
thread’s Worker.
Use this to initialize or re-initialize per-thread state via Worker::init.
Only num_threads threads execute the closure; the rest skip it.
Sourcepub fn install<R: Send>(&self, f: impl FnOnce(&Worker) -> R + Send) -> R
pub fn install<R: Send>(&self, f: impl FnOnce(&Worker) -> R + Send) -> R
Runs a closure on the pool with access to the calling thread’s Worker.
All rayon parallelism (e.g. par_iter) spawned inside the closure executes on this pool.
Each thread can access its own Worker via the provided reference or through additional
WorkerPool::with_worker calls.
Sourcepub fn install_fn<R: Send>(&self, f: impl FnOnce() -> R + Send) -> R
pub fn install_fn<R: Send>(&self, f: impl FnOnce() -> R + Send) -> R
Sourcepub fn in_place_scope<'scope, R>(
&self,
f: impl FnOnce(&Scope<'scope>) -> R,
) -> R
pub fn in_place_scope<'scope, R>( &self, f: impl FnOnce(&Scope<'scope>) -> R, ) -> R
Executes f on this pool using [rayon::in_place_scope], which converts the calling
thread into a worker for the duration — tasks spawned inside the scope run on the pool
and the call blocks until all of them complete.
Sourcepub fn with_worker<R>(f: impl FnOnce(&Worker) -> R) -> R
pub fn with_worker<R>(f: impl FnOnce(&Worker) -> R) -> R
Sourcepub fn with_worker_mut<R>(f: impl FnOnce(&mut Worker) -> R) -> R
pub fn with_worker_mut<R>(f: impl FnOnce(&mut Worker) -> R) -> R
Mutably access the current thread’s Worker from within a pool closure.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WorkerPool
impl !RefUnwindSafe for WorkerPool
impl Send for WorkerPool
impl Sync for WorkerPool
impl Unpin for WorkerPool
impl UnsafeUnpin for WorkerPool
impl !UnwindSafe for WorkerPool
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 8 bytes