5 个版本 (3 个重大更新)
0.4.0 | 2021年1月16日 |
---|---|
0.3.1 | 2021年1月15日 |
0.3.0 | 2021年1月15日 |
0.2.0 | 2021年1月14日 |
0.1.0 | 2021年1月14日 |
#12 in #spmc
每月下载量 53
10KB
171 代码行
threaded
Rust 中的极简线程池
原型代码简洁易读,适合追求简洁性和透明度的开发者。
稳定性
实验性
Threaded 没有完全覆盖也没有经过基准测试,更不用说比较性性能测试。
分支策略
使用方法
use threaded::ThreadPool;
// start thread pool with fixed capacity of 2 workers (single producer, multiple consumer; spmc)
let tp = ThreadPool::new(2);
tp.execute(|| println!("hello threaded!")); // execute function in pool
let _num_workers = tp.capacity(); // get capacity of pool
// once tp goes out of scope, drop is called
// drop joins worker threads subsequently blocking main thread until workers finish
drop(tp); // manually trigger drop and join threads
请参阅 docs.rs/threaded。
致谢
Rust 编程语言书籍 详细介绍了开始编写有用程序所需的基本功能,同时遵守社区规范。Threaded 是基于书籍的最终项目 "构建一个多线程 Web 服务器" 直接开发的。
许可证
依赖项
~0.5–1MB
~17K SLoC