ThreadPool

Struct ThreadPool 

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

Simple thread pool to allow benchmarks to run on pre-warmed threads instead of creating new threads for every batch of iterations. Thread reuse reduces benchmark harness overhead.

Threads in the pool are bound to specific processors according to the provided processor set, ensuring consistent processor affinity across benchmark runs.

§Examples

use many_cpus::ProcessorSet;
use new_zealand::nz;
use par_bench::ThreadPool;

// Create a thread pool using the default processor set
let pool = ThreadPool::new(&ProcessorSet::default());
println!("Default pool has {} threads", pool.thread_count());

// Create a thread pool with a specific processor set
if let Some(processors) = ProcessorSet::builder().take(nz!(2)) {
    let pool = ThreadPool::new(&processors);
    assert_eq!(pool.thread_count().get(), 2);
}

§Lifecycle

Dropping the pool will wait for all threads to finish executing their tasks.

Implementations§

Source§

impl ThreadPool

Source

pub fn new(processors: impl AsRef<ProcessorSet>) -> Self

Creates a thread pool with one thread per processor in the provided processor set.

Each thread will be bound to its corresponding processor, ensuring consistent processor affinity for benchmark execution.

§Examples
use many_cpus::ProcessorSet;
use new_zealand::nz;
use par_bench::ThreadPool;

// Create pool with specific processors
if let Some(processors) = ProcessorSet::builder().take(nz!(4)) {
    let pool = ThreadPool::new(&processors);
    assert_eq!(pool.thread_count().get(), 4);
}
Source

pub fn thread_count(&self) -> NonZero<usize>

Returns the number of threads in the pool.

This is always equal to the number of processors in the processor set used to create the pool.

§Examples
use many_cpus::ProcessorSet;
use par_bench::ThreadPool;

let pool = ThreadPool::new(&ProcessorSet::default());
println!("Pool has {} worker threads", pool.thread_count());

Trait Implementations§

Source§

impl Debug for ThreadPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V