pub struct ThreadManager<T>where
T: Send + 'static,{ /* private fields */ }
Expand description
A dynamic dispatch version of ThreadManagerCore
for managing threads that execute functions
returning a specific type T
.
§Type Parameters
T
: The type of the value returned by the functions executed by the threads.
Implementations§
Source§impl<T> ThreadManager<T>where
T: Send + 'static,
impl<T> ThreadManager<T>where
T: Send + 'static,
Sourcepub fn new_asymmetric(size: usize, wpc: usize) -> Self
pub fn new_asymmetric(size: usize, wpc: usize) -> Self
Sourcepub fn join(&self)
pub fn join(&self)
Joins all worker threads, effectively blocking the current thread until all worker threads have completed their execution.
§Note
This method will block the current thread until all worker threads have finished processing their jobs.
Sourcepub fn terminate_all(&self)
pub fn terminate_all(&self)
Terminates all worker threads gracefully.
§Note
This method will block until the currently executing job among threads is completed.
Sourcepub fn job_distribution(&self) -> Vec<usize>
pub fn job_distribution(&self) -> Vec<usize>
Provides the job distribution across the worker threads.
§Returns
A vector containing the count of jobs executed by each worker thread.
Sourcepub fn has_finished(&self) -> bool
pub fn has_finished(&self) -> bool
Sourcepub fn results<'a>(&'a self) -> ResultIter<'a, T> ⓘ
pub fn results<'a>(&'a self) -> ResultIter<'a, T> ⓘ
Retrieves an iterator over the results of completed jobs.
§Returns
An iterator (ResultIter
) over the results of the jobs that have been completed.
Sourcepub fn yield_results<'a>(
&'a self,
) -> YieldResultIter<'a, Box<dyn Fn() -> T + Send + 'static>, T> ⓘ
pub fn yield_results<'a>( &'a self, ) -> YieldResultIter<'a, Box<dyn Fn() -> T + Send + 'static>, T> ⓘ
Retrieves an iterator that yields results as they become available.
§Returns
An iterator (YieldResultIter
) that yields results from worker threads.
This method blocks for each result until the job queue is complete.
Sourcepub fn active_threads(&self) -> usize
pub fn active_threads(&self) -> usize
Returns the number of active worker threads (both busy and waiting).
§Returns
The total number of active worker threads.
Sourcepub fn busy_threads(&self) -> usize
pub fn busy_threads(&self) -> usize
Returns the number of worker threads that are currently busy executing a job.
§Returns
The number of busy worker threads.
Sourcepub fn waiting_threads(&self) -> usize
pub fn waiting_threads(&self) -> usize
Returns the number of worker threads that are currently waiting for a job.
§Returns
The number of waiting worker threads.
Sourcepub fn job_queue(&self) -> usize
pub fn job_queue(&self) -> usize
Returns the number of jobs currently in the queue waiting to be executed.
§Returns
The size of the job queue.
Sourcepub fn sent_jobs(&self) -> usize
pub fn sent_jobs(&self) -> usize
Returns the total number of jobs that have been sent to worker threads.
§Returns
The number of sent jobs.
Sourcepub fn received_jobs(&self) -> usize
pub fn received_jobs(&self) -> usize
Returns the total number of jobs that have been received by worker threads.
§Returns
The number of received jobs.
Sourcepub fn concluded_jobs(&self) -> usize
pub fn concluded_jobs(&self) -> usize
Returns the total number of jobs that have been concluded by worker threads.
§Returns
The number of concluded jobs.