1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use scoped_pool::Pool;

#[derive(Clone, Copy, Debug)]
pub struct BMConfig {
    runners: i32,
}

impl BMConfig {
    pub fn new(runners: i32) -> Self {
        Self { runners }
    }

    pub fn step(&self, runners: i32) -> Self {
        Self {
            runners: self.runners + runners,
        }
    }
}

pub fn bmexec(config: BMConfig, f: impl FnOnce() + Send + Clone) {
    let pool = Pool::new(config.runners as usize);

    pool.scoped(|scope| {
        for _ in 0..config.runners {
            scope.execute(f.clone());
        }
    });
}