Crates.io | swimming-pool |
lib.rs | swimming-pool |
version | 0.1.4 |
source | src |
created_at | 2024-02-25 08:16:44.650419 |
updated_at | 2024-03-01 12:11:18.696783 |
description | A simple threadpool for running a number of jobs on a fixed number of threads. |
homepage | |
repository | https://github.com/Pranjal-Patel/swimming-pool |
max_upload_size | |
id | 1152283 |
size | 40,609 |
A simple threadpool for running a number of jobs on a fixed number of threads.
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();
}