#thread-pool #worker-thread #numbers #fixed #jobs #running #swimming

swimming-pool

A simple threadpool for running a number of jobs on a fixed number of threads

5 releases

0.1.4 Mar 1, 2024
0.1.3 Feb 27, 2024
0.1.2 Feb 26, 2024
0.1.1 Feb 25, 2024
0.1.0 Feb 25, 2024

#473 in Concurrency

Download history 421/week @ 2024-02-24 43/week @ 2024-03-02 6/week @ 2024-03-09 1/week @ 2024-03-16 30/week @ 2024-03-30 27/week @ 2024-04-06

57 downloads per month

GPL-3.0-only

15KB
84 lines

Swimming pool

A simple threadpool for running a number of jobs on a fixed number of threads.

Example usage

Add it to your project

$ cargo add swimming-pool

Example code

use std::thread;
use std::time::Duration;

use swimming_pool::ThreadPool;

fn main() {
    // Create a thread pool with 5 worker threads
    let pool = ThreadPool::new(5);

    // Spawn 5 jobs
    for _ in 0..5 {
        pool.execute(|| {
            thread::sleep(Duration::from_secs(5));
            println!("Printing after 5 seconds");
        })
    }

    pool.join_all();
}

lib.rs:

Sorry I couldn't come up with a better name.

No runtime deps