pub trait WorkerManager: Manager + 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
Manager that also has a thread pool
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.