Crate threadfin

source ·
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

A builder for constructing a customized ThreadPool.
An error returned when attempting to configure the common thread pool after it has already been initialized.
Modifies a size constraint to be per available CPU core.
An error returned when a task could not be executed because a thread pool was full.
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.
A thread pool for running multiple tasks on a configurable group of threads.

Traits

A value describing a size constraint for a thread pool.

Functions

Get a builder for creating a customized thread pool.
Get a shared reference to a common thread pool for the entire process.
Configure the common thread pool.