pub trait GenericThreadpool<'scope, I, O>:
IntoIterator<Item = O>
+ Extend<I>
+ Sized
+ Send
+ Sync {
type Iter<'a>: Iterator<Item = O> + 'a
where Self: 'a;
type JoinHandle;
// Required methods
fn submit(&self, input: I);
fn recv(&self) -> O;
fn try_recv(&self) -> Option<O>;
fn iter(&self) -> Self::Iter<'_>;
fn wait_until_finished(&self);
fn producer<T>(&self, iter: T) -> Self::JoinHandle
where T: IntoIterator<Item = I> + Send + Sync + 'scope;
fn consumer<F>(&self, f: F) -> Self::JoinHandle
where F: Fn(O) + Sync + Send + 'scope;
// Provided method
fn submit_all<T>(&self, iter: T)
where T: IntoIterator<Item = I> { ... }
}
Expand description
Generic trait representing a thread pool.
See Threadpool
and OrderedThreadpool
for specific implementations.
Required Associated Types§
type Iter<'a>: Iterator<Item = O> + 'a where Self: 'a
type JoinHandle
Required Methods§
Sourcefn recv(&self) -> O
fn recv(&self) -> O
Block the current thread until a result from the pool is available, and return it.
Sourcefn try_recv(&self) -> Option<O>
fn try_recv(&self) -> Option<O>
Check if a result is available from the pool;
if so, return it. If not, returns None
.
Sourcefn iter(&self) -> Self::Iter<'_>
fn iter(&self) -> Self::Iter<'_>
Iterate over the currently available results in the pool.
Does not consume the pool; it only yields results until there are no jobs left to process. If more jobs are submitted to the pool afterwards, those results may be subsequently iterated over as well.
It’s recommended that you call GenericThreadpool::wait_until_finished
before iterating, otherwise the cpu may be stuck in a busy wait while
lingering jobs are still being processed.
Sourcefn wait_until_finished(&self)
fn wait_until_finished(&self)
Block until all producers have been exhausted, and all workers have finished processing all jobs.
Sourcefn producer<T>(&self, iter: T) -> Self::JoinHandle
fn producer<T>(&self, iter: T) -> Self::JoinHandle
Spawn a new producer thread, which supplies jobs to the pool from the passed iterator asynchronously on a separate thread.
Provided Methods§
Sourcefn submit_all<T>(&self, iter: T)where
T: IntoIterator<Item = I>,
fn submit_all<T>(&self, iter: T)where
T: IntoIterator<Item = I>,
Synchronously submit many jobs to the pool at once from an iterator or collection.
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.