PoolConfig

Struct PoolConfig 

Source
pub struct PoolConfig {
    pub n_workers: u16,
    pub max_jobs: Option<u16>,
    pub incoming_buf_size: Option<u16>,
}
Expand description

Pool Config

Configuration for the ThreadPool

Fields§

§n_workers: u16§max_jobs: Option<u16>§incoming_buf_size: Option<u16>

Implementations§

Source§

impl PoolConfig

Source

pub const fn builder() -> PoolConfigBuilder

Examples found in repository?
examples/scopes.rs (line 9)
8pub fn main() {
9    let conf = PoolConfig::builder().max_jobs(16).build();
10    let pool = ThreadPool::new(conf).unwrap();
11
12    let nums = (0..1000).collect::<Vec<_>>();
13
14    let n = Mutex::new(0);
15
16    fn delay() {
17        use core::hash::BuildHasher;
18        let rand = RandomState::new().build_hasher().finish();
19        let millis = rand % 500;
20        std::thread::sleep(Duration::from_millis(1000 + millis));
21    }
22
23    pool.scope(|scope| {
24        scope.subscope(|sc| {
25            sc.execute(|| {
26                delay();
27                *n.lock().unwrap() += nums.iter().sum::<usize>();
28                println!("Sum1");
29            });
30            sc.execute(|| {
31                delay();
32                *n.lock().unwrap() += nums.iter().filter(|n| *n % 2 == 0).sum::<usize>();
33                println!("Sum even");
34            });
35        });
36
37        scope.subscope(|sc| {
38            sc.execute(|| {
39                delay();
40                *n.lock().unwrap() *= nums.iter().max().unwrap();
41                println!("Mul max");
42            });
43
44            sc.execute(|| {
45                delay();
46                *n.lock().unwrap() *= nums[nums.len() / 2];
47                println!("Mul mid");
48            });
49        });
50    });
51
52    let mut expected = 0;
53    expected += nums.iter().sum::<usize>();
54    expected += nums.iter().filter(|n| *n % 2 == 0).sum::<usize>();
55    expected *= nums.iter().max().unwrap();
56    expected *= nums[nums.len() / 2];
57
58    let n = *n.lock().unwrap();
59    assert_eq!(n, expected);
60    println!("{n} == {expected}");
61}
Source

pub fn validate(&self) -> Result<()>

Trait Implementations§

Source§

impl Clone for PoolConfig

Source§

fn clone(&self) -> PoolConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PoolConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for PoolConfig

Source§

fn default() -> Self

Default configuration

Nº Workers: 16 Max Jobs: None Incoming buf size: None

Source§

impl Copy for PoolConfig

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.