ThreadPool

Trait ThreadPool 

Source
pub trait ThreadPool: Send + Sync {
    // Required methods
    fn num_threads(&self) -> usize;
    fn execute<F>(&self, f: F)
       where F: FnOnce() + Send + 'static;
    fn join<A, B, RA, RB>(&self, a: A, b: B) -> (RA, RB)
       where A: FnOnce() -> RA + Send,
             B: FnOnce() -> RB + Send,
             RA: Send,
             RB: Send;
    fn for_each<F>(&self, range: Range<usize>, f: F)
       where F: Fn(usize) + Send + Sync;
    fn map_reduce<T, Map, Reduce>(
        &self,
        range: Range<usize>,
        identity: T,
        map: Map,
        reduce: Reduce,
    ) -> T
       where T: Clone + Send + Sync,
             Map: Fn(usize) -> T + Send + Sync,
             Reduce: Fn(T, T) -> T + Send + Sync;
}
Expand description

Trait for custom thread pool implementations.

This allows using thread pools other than rayon’s global pool.

Required Methods§

Source

fn num_threads(&self) -> usize

Returns the number of threads in the pool.

Source

fn execute<F>(&self, f: F)
where F: FnOnce() + Send + 'static,

Executes a closure on the thread pool.

Source

fn join<A, B, RA, RB>(&self, a: A, b: B) -> (RA, RB)
where A: FnOnce() -> RA + Send, B: FnOnce() -> RB + Send, RA: Send, RB: Send,

Joins two closures, executing them potentially in parallel.

Source

fn for_each<F>(&self, range: Range<usize>, f: F)
where F: Fn(usize) + Send + Sync,

Parallel for_each over a range.

Source

fn map_reduce<T, Map, Reduce>( &self, range: Range<usize>, identity: T, map: Map, reduce: Reduce, ) -> T
where T: Clone + Send + Sync, Map: Fn(usize) -> T + Send + Sync, Reduce: Fn(T, T) -> T + Send + Sync,

Parallel map-reduce over a range.

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.

Implementors§