Cargo.toml
toml
[dependencies]
poolite = "0.3.0"
or
toml
[dependencies]
poolite = { git = "https://github.com/biluohc/poolite",branch = "master", version = "0.3.0" }
poolite::Pool::new()
create a thread_pool. min()
receive usize
as minimum number of threads in pool,default is cpu's number+1.time_out()
receive u64
as thread's idle time(ms) except minimum number of threads,default is 5000(ms).name()
receive AsRef<str>
as thread's name,default is None.stack_size()
receive usize
as thread's stack_size,default depends on OS.load_limit()
receive usize
as the loadlimit, pool will create new thread while tasks_queue_len()/threads
bigger than it,default is cpu's number. min()
is 0 and load_limit()
is'not 0,until tasks_queue_len()/threads
bigger than loadlimit.run()
let pool to start run(Add number of min threads to the pool). spawn()
receive Box<Fn() + Send + 'static>
,Box<FnMut() + Send + 'static>
and Box<FnOnce() + Send + 'static>
(Box<FnBox() + Send + 'static>
). len()
return a usize of the thread'number in pool. wait_len()
return a usize of the thread'number that is waiting in pool tasks_len()
return a usize of the length of the tasks_queue. is_empty()
return a bool, all threads are waiting and tasks_queue'length is 0. ```Rust extern crate poolite;
use std::collections::BTreeMap; use std::sync::{Arc, Mutex}; use std::time::Duration; use std::thread;
fn main() {
let pool = poolite::Pool::new().run();
let map = Arc::new(Mutex::new(BTreeMap::
unwrap()
and add load_limit(),is_empty(), tasks_len(), len(), wait_len(), strong_count()
methods.FnBox()
to support FnOnce()
(Only support Nightly now,Stable or Beta should use 0.2.0).min(),time_out(),name(),stack_size(),run()
methods.