pub struct ThreadPool { /* private fields */ }
Expand description
Thread pool used in multi-threaded pconvert calls.
Implementations§
Source§impl ThreadPool
impl ThreadPool
Sourcepub fn new(size: usize) -> Result<ThreadPool, PConvertError>
pub fn new(size: usize) -> Result<ThreadPool, PConvertError>
Creates a thread pool with size
worker threads.
Sourcepub fn execute<F>(&self, func: F) -> Receiver<ResultMessage>
pub fn execute<F>(&self, func: F) -> Receiver<ResultMessage>
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();
Sourcepub fn expand_to(&mut self, num_threads: usize)
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
.
pub fn get_status(&self) -> ThreadPoolStatus
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ThreadPool
impl !RefUnwindSafe for ThreadPool
impl Send for ThreadPool
impl Sync for ThreadPool
impl Unpin for ThreadPool
impl !UnwindSafe for ThreadPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more