pub trait WorkerPool: Sync {
// Required methods
fn current_num_threads(&self) -> usize;
fn split_depth(&self) -> u32;
fn set_split_depth(&self, depth: Option<u32>);
fn install<R: Send>(&self, op: impl FnOnce() -> R + Send) -> R;
fn join<RA: Send, RB: Send>(
&self,
op_a: impl FnOnce() -> RA + Send,
op_b: impl FnOnce() -> RB + Send,
) -> (RA, RB);
fn broadcast<R: Send>(
&self,
op: impl Fn(BroadcastContext) -> R + Sync,
) -> Vec<R>;
}
Expand description
Worker thread pool associated with a Manager
A manager having its own thread pool has the advantage that it may use thread-local storage for its workers to pre-allocate some resources (e.g., slots for nodes) and thereby reduce lock contention.
Required Methods§
Sourcefn current_num_threads(&self) -> usize
fn current_num_threads(&self) -> usize
Get the current number of threads
Sourcefn split_depth(&self) -> u32
fn split_depth(&self) -> u32
Get the recursion depth up to which operations are split
Sourcefn set_split_depth(&self, depth: Option<u32>)
fn set_split_depth(&self, depth: Option<u32>)
Set the recursion depth up to which operations are split
None
means that the implementation should automatically choose the
depth. Some(0)
means that no operations are split.
Sourcefn install<R: Send>(&self, op: impl FnOnce() -> R + Send) -> R
fn install<R: Send>(&self, op: impl FnOnce() -> R + Send) -> R
Execute op
within the thread pool
If this method is called from another thread pool, it may cooperatively
yield execution to that pool until op
has finished.
Sourcefn join<RA: Send, RB: Send>(
&self,
op_a: impl FnOnce() -> RA + Send,
op_b: impl FnOnce() -> RB + Send,
) -> (RA, RB)
fn join<RA: Send, RB: Send>( &self, op_a: impl FnOnce() -> RA + Send, op_b: impl FnOnce() -> RB + Send, ) -> (RA, RB)
Execute op_a
and op_b
in parallel within the thread pool
Note that the split depth has no influence on this method. Checking whether to split an operation must be done externally.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.