Threadpool
Threadpool provides a way to manage and execute tasks concurrently using a fixed number of worker threads. It allows you to submit tasks that will be executed by one of the available worker threads, providing an efficient way to parallelize work across multiple threads.
Maintaining a pool of threads over creating a new thread for each task has the benefit that thread creation and destruction overhead is restricted to the initial creation of the pool.
The implementation is dependency and unsafe
-free.
Usage
use ;
use ;
let thread_pool = default.build;
let value = new;
.for_each;
You can create a ThreadPool using the builder pattern:
use ThreadPool;
let pool = builder.build;
let custom_pool = builder
.num_threads
.stack_size
.name_prefix
.build;
Use the execute method to submit tasks to the thread pool:
pool.execute;
To wait for all tasks to complete:
pool.join;
License
MIT