Crate foofighters

Crate foofighters 

Source
Expand description

§foofighters

A lightweight, work-stealing thread pool.

§Example

Add this crate using cargo add foofighters:

use foofighters::pool::PoolBuilder;

let pool = PoolBuilder::new()
    .set_worker_count(4)
    .set_steal_amount(2)
    .build();

let submission = pool.spawn(|| {
    println!("Hello from a worker!");
});

submission.into_result().unwrap();

§Lifecycle

Each worker thread runs this cycle:

  1. Execute all tasks in its local queue.
  2. Steal from the global queue if empty.
  3. Attempt to steal batches from other workers.
  4. Park when no work remains (and unpark when new tasks arrive).
  5. On shutdown, drain any remaining global tasks before exiting.

§Shutdown

When the Pool instance is dropped:

  • Task submissions are automatically blocked.
  • All worker threads are unparked.
  • Each worker drains any remaining global tasks.
  • The pool joins all threads before returning control.

§Tests

cargo test

Or just check compilation without running them as running it will spawn threads:

cargo test --doc --no-run

§License

MIT

Modules§

pool
Thread Pool Module