Crate base_threadpool

Source
Expand description

Threadpool provides a way to manage and execute tasks concurrently using a fixed number of worker threads. It allows you to submit tasks that will be executed by one of the available worker threads, providing an efficient way to parallelize work across multiple threads.

Maintaining a pool of threads over creating a new thread for each task has the benefit that thread creation and destruction overhead is restricted to the initial creation of the pool.

§Examples

use base_threadpool::{ThreadPool, ThreadPoolBuilder};
use std::sync::{Arc, Mutex};

let thread_pool = ThreadPoolBuilder::default().build();
let value = Arc::new(Mutex::new(0));

(0..4).for_each(move |_| {
    let value = Arc::clone(&value);
    thread_pool.execute(move || {
        let mut ir = 0;
        (0..100_000_000).for_each(|_| {
            ir += 1;
        });

        let mut lock = value.lock().unwrap();
        *lock += ir;
    });
});

Structs§

ThreadPool
ThreadPool provides a way to manage and execute tasks concurrently using a fixed number of worker threads.
ThreadPoolBuilder
A builder for configuring and creating a ThreadPool.