A lite thread pool library written for Rust.
Usage
Cargo.toml
[]
= "0.2.1"
or
[]
= { = "https://github.com/biluohc/poolite", = "master", = "0.2.1" }
Explain
Create a thread pool:
- use
poolite::Pool::new()
create a thread_pool.
The following are optional:
min()
receiveusize
as minimum number of threads in pool,default is cpu's number.time_out()
receiveu64
as thread's idle time(ms) except minimum number of threads,default is 5000(ms).name()
receive&str
as thread's name,default is None.stack_size()
receiveusize
as thread's stack_size,default depends on OS.
Let thread pool to start run:
run()
let pool to start run.
Add a task to the thread pool:
spawn()
receiveBox<Fn() + Send>
,Box<FnMut() + Send>
andBox<FnOnce() + Send>
(Box<FnBox()+Send>
).- while leave scope,pool will drop automatically.
Example
extern crate poolite;
use Duration;
use thread;