Expand description
Lagoon is a thread pool crate that aims to address many of the problems with existing thread pool crates.
§Features
- Scoped jobs: Safely spawn jobs that have access to their parent scope!
- Job handles: Receive the result of a job when it finishes, or wait on it to finish!
- Global pool: A pay-for-what-you-use global thread pool that avoids dependencies fighting over resources!
- Customise thread attributes: Specify thread name, stack size, etc.
ⓘ
let pool = lagoon::ThreadPool::default();
// Spawn some jobs that notify us when they're finished
let jobs = (0..10)
.map(|i| pool.run_recv(move || {
println!("Hello! i = {}", i);
}))
.collect::<Vec<_>>();
// Wait for all jobs to finish
for job in jobs {
job.join().unwrap();
}
Structs§
- JobHandle
recv
- A handle that refers to a job that notifies on completion. It may be created with
ThreadPool::run_recv
. - Scope
scope
- A scope within which jobs that refer to their parent scope may safely be spawned.
- Thread
Pool - A pool of threads that may be used to execute jobs.
- Thread
Pool Builder - A type used to configure a
ThreadPool
prior to its creation.
Enums§
- Error
- An error that may be produced when creating a
ThreadPool
.
Functions§
- available_
concurrency - Attempt to determine the available concurrency of the host system.