pub struct ThreadPool { /* private fields */ }Expand description
Thread pool for executing work in parallel
This matches the C++ thread_pool class with similar functionality:
- Fixed number of worker threads
- Work queue
- Parallel for loop support
Implementations§
Source§impl ThreadPool
impl ThreadPool
Sourcepub fn new(nthreads: usize) -> Self
pub fn new(nthreads: usize) -> Self
Create a new thread pool with the specified number of threads
Sourcepub fn submit<F, R, Args>(&self, f: F, args: Args) -> Receiver<R>
pub fn submit<F, R, Args>(&self, f: F, args: Args) -> Receiver<R>
Submit a function to be executed by the thread pool
Returns a receiver that can be used to get the result
Sourcepub fn parallel_for<F>(&self, start: usize, end: usize, stride: usize, f: F)
pub fn parallel_for<F>(&self, start: usize, end: usize, stride: usize, f: F)
Execute a parallel for loop over a range
This matches the C++ thread_pool::parallel_for method
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 UnsafeUnpin 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