Expand description
A thread pool for running multiple tasks on a configurable group of threads.
Extra features:
- Dynamic pool size based on load
- Support for async tasks
- Tasks return a handle which can be joined or awaited for the return value
- Optional common process-wide thread pool
§Async support
Threadfin supports asynchronous usage via futures, and allows you to mix and match both synchronous and asynchronous tasks within a single thread pool.
§Examples
// Create a new pool.
let pool = threadfin::builder().size(8).build();
// Schedule some work.
let compute_task = pool.execute(|| {
// Some expensive computation
2 + 2
});
// Do something in the meantime.
println!("Waiting for result...");
// Wait for the task to complete and get the result.
let sum = compute_task.join();
println!("Sum: 2 + 2 = {}", sum);
Structs§
- Builder
- A builder for constructing a customized
ThreadPool
. - Common
Already Initialized Error - An error returned when attempting to configure the common thread pool after it has already been initialized.
- PerCore
- Modifies a size constraint to be per available CPU core.
- Pool
Full Error - An error returned when a task could not be executed because a thread pool was full.
- Task
- A type of future representing the result of a background computation in a thread pool. Tasks are returned when submitting a closure or future to a thread pool.
- Thread
Pool - A thread pool for running multiple tasks on a configurable group of threads.
Traits§
- Size
Constraint - A value describing a size constraint for a thread pool.
Functions§
- builder
- Get a builder for creating a customized thread pool.
- common
- Get a shared reference to a common thread pool for the entire process.
- configure_
common - Configure the common thread pool.