shrink_pool 1.0.0

A thread pool which agressively terminates its threads as soon as they are idle.
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented3 out of 7 items with examples
  • Size
  • Source code size: 14.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.52 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • dochy-ksti/shrink_pool
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dochy-ksti

ShrinkPool

A thread pool which agressively terminates its threads as soon as they are idle.

If there are queued tasks, OS threads are spawned until the pool is full.

When all tasks have been done, no threads are running on the pool.

The tasks start in a FIFO(First-In-First-Out) manner. No workstealing occurs.

However, the order in which tasks are completed depends on the OS.

use shrink_pool::ShrinkPool;
use num_cpus;

let pool = ShrinkPool::new(num_cpus::get());

for i in 0..10 {
    pool.execute(move || println!("task {i} is processing..."))
}
Result:
Task 0 is processing...
Task 2 is processing...
Task 5 is processing...
Task 6 is processing...
Task 7 is processing...
Task 8 is processing...
Task 9 is processing...
Task 3 is processing...
Task 4 is processing...
Task 1 is processing...

If you want to synchronize tasks, you can use SyncThread.

It's basically a thread pool which has only one thread, and the thread is terminated when it's not running.

use shrink_pool::SyncThread;
   
let thread = SyncThread::new();

for i in 0..10 {
    thread.execute(move || print!("{i},"))
}
Result: 
0,1,2,3,4,5,6,7,8,9,

Motivation

I don't like libralies which silently spawn global threads and make them wait. I want to clean them up when they are not running.

License

Licensed under either of