Struct ThreadPool

Source
pub struct ThreadPool { /* private fields */ }
Expand description

Thread pool used in multi-threaded pconvert calls.

Implementations§

Source§

impl ThreadPool

Source

pub fn new(size: usize) -> Result<ThreadPool, PConvertError>

Creates a thread pool with size worker threads.

Source

pub fn start(&mut self)

Begin execution of worker threads.

Source

pub fn execute<F>(&self, func: F) -> Receiver<ResultMessage>
where F: FnOnce() -> ResultMessage + Send + 'static,

Enqueues a task for execution by any of the worker threads.

§Arguments
  • func - The task to execute.
§Return

Returns the receiver end of a channel where the result will be placed.

§Examples
use pconvert_rust::parallelism::{ResultMessage, ThreadPool};
use pconvert_rust::utils::read_png_from_file;

let mut thread_pool = ThreadPool::new(10).unwrap();
let path = "path/to/file.png".to_owned();
let demultiply = false;
let result_channel = thread_pool.execute(move || ResultMessage::ImageResult(read_png_from_file(path, demultiply)));
let top = match result_channel.recv().unwrap() {
    ResultMessage::ImageResult(result) => result,
}.unwrap();
Source

pub fn expand_to(&mut self, num_threads: usize)

Expands the thread pool to num_threads. Creates n workers, where n = num_threads - thread_pool_size.

Source

pub fn get_status(&self) -> ThreadPoolStatus

Trait Implementations§

Source§

impl Drop for ThreadPool

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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.
Source§

impl<T> Ungil for T
where T: Send,