Struct ThreadManagerCore

Source
pub struct ThreadManagerCore<F, T>
where F: Fn() -> T + Send + 'static, T: Send + 'static,
{ /* private fields */ }
Expand description

A thread manager for executing jobs in parallel. This struct manages a pool of worker threads and distributes jobs among them.

§Type Parameters

  • F: The type of the function or closure that the threads will execute.
  • T: The type of the value returned by the function or closure.

§Fields

  • wpc: The number of Workers-Per-Channel.
  • dispatch: An instance of DispatchCycle to manage job distribution.
  • workers: A vector of ThreadWorker instances representing the worker threads.
  • channels: A vector of job channels for dispatching jobs to workers.
  • result_channel: A channel for collecting the results of the jobs.
  • manager_status: An instance of ManagerStatus to track the status of the manager.

Implementations§

Source§

impl<F, T> ThreadManagerCore<F, T>
where F: Fn() -> T + Send + 'static, T: Send + 'static,

Source

pub fn new(size: usize) -> Self

Creates a new instance of ThreadManagerCore with a specified number of worker threads.

§Arguments
  • size: The number of worker threads to create.
§Returns

A new instance of ThreadManagerCore.

Source

pub fn new_asymmetric(size: usize, wpc: usize) -> Self

Creates a new instance of ThreadManagerCore with a specified number of worker threads and a specific workers-per-channel ratio.

§Arguments
  • size: The number of worker threads to create.
  • wpc: The number of workers per channel.
§Returns

A new instance of ThreadManagerCore with the specified configuration.

Source

pub fn execute(&self, function: F)

Executes a given function by sending it to an available worker thread.

§Arguments
  • function: The function to be executed by the worker thread.
Source

pub fn resize(&mut self, size: usize)

Resizes the pool of worker threads.

§Arguments
  • size: The new size of the worker pool.
Source§

impl<F, T> ThreadManagerCore<F, T>
where F: Fn() -> T + Send + 'static, T: Send + 'static,

Source

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.

Source

pub fn terminate_all(&self)

Terminates all worker threads gracefully.

§Note

This method will block until the currently executing job among threads is completed.

Source

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.

Source

pub fn has_finished(&self) -> bool

Checks if all jobs have been finished.

§Returns

true if all jobs are finished, false otherwise.

Source

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.

Source

pub fn yield_results<'a>(&'a self) -> YieldResultIter<'a, F, 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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<F, T> Drop for ThreadManagerCore<F, T>
where F: Fn() -> T + Send + 'static, T: Send + 'static,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<F, T> !Freeze for ThreadManagerCore<F, T>

§

impl<F, T> !RefUnwindSafe for ThreadManagerCore<F, T>

§

impl<F, T> Send for ThreadManagerCore<F, T>

§

impl<F, T> !Sync for ThreadManagerCore<F, T>

§

impl<F, T> Unpin for ThreadManagerCore<F, T>

§

impl<F, T> !UnwindSafe for ThreadManagerCore<F, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.