|
| 1 | +<p align="left"> |
| 2 | + <a href="https://github.com/ChunelFeng/CThreadPool"><img src="https://badgen.net/badge/langs/C++/cyan?list=1" alt="languages"></a> |
| 3 | + <a href="https://github.com/ChunelFeng/CThreadPool"><img src="https://badgen.net/badge/os/MacOS,Linux,Windows/cyan?list=1" alt="os"></a> |
| 4 | + <a href="https://github.com/ChunelFeng/CThreadPool/stargazers"><img src="https://badgen.net/github/stars/ChunelFeng/CThreadPool?color=cyan" alt="stars"></a> |
| 5 | + <a href="https://github.com/ChunelFeng/CThreadPool/network/members"><img src="https://badgen.net/github/forks/ChunelFeng/CThreadPool?color=cyan" alt="forks"></a> |
| 6 | +</p> |
| 7 | + |
| 8 | +<h1 align="center"> |
| 9 | + CThreadPool 说明文档 |
| 10 | +</h1> |
| 11 | + |
| 12 | +## 一. 简介 |
| 13 | +`CThreadPool` 是一个跨平台的、无任何三方依赖的、高性能的C++14(含以上版本)版本的线程池,也是 [CGraph](https://github.com/ChunelFeng/CGraph) 项目中使用的跨平台线程池组件功能的最小集。 |
| 14 | + |
| 15 | +经过CGraph和关联项目的长期迭代和验证,功能已经趋于稳定,且性能优异。因为咨询相关内容的朋友较多,故做为独立的仓库提供出来,方便大家使用。 |
| 16 | + |
| 17 | +由于是CGraph项目中的剥离出来的功能类,故在项目中保留了多处 `CGRAPH_*` 的命名方式,仅将 namespace 修改为 `CTP`,预计今后与CGraph相互独立更新。 |
| 18 | + |
| 19 | +本项目参考了[《C++并发编程实战(第二版)》](https://nj.gitbooks.io/c/content/) 中的部分内容,和github上部分相关的优秀工程。并在此基础上进行大量的改动、扩展和优化,在功能、性能和易用性上均有较大的提升。 |
| 20 | + |
| 21 | +在开发过程中,也沉淀了详细的说明文档(见下方 <b>推荐阅读</b>),以便于大家快速了解代码和思路,也请大家不吝指教。 |
| 22 | + |
| 23 | +## 二. 编译说明 |
| 24 | +* 本工程支持MacOS、Linux和Windows系统,无任何第三方依赖。推荐使用C++14(默认)或以上版本,不支持C++11或以下版本 |
| 25 | + |
| 26 | +* 使用CLion作为IDE的开发者,或使用Visual Studio 15(或以上版本)作为IDE的开发者,打开CMakeLists.txt文件作为工程,即可编译通过 |
| 27 | + |
| 28 | +* Linux环境开发者,在命令行模式下,输入以下指令,即可编译通过 |
| 29 | +```shell |
| 30 | +$ git clone https://github.com/ChunelFeng/CThreadPool.git |
| 31 | +$ cd CThreadPool |
| 32 | +$ cmake . -Bbuild |
| 33 | +$ cd build |
| 34 | +$ make -j8 |
| 35 | +``` |
| 36 | + |
| 37 | +## 三. 使用Demo |
| 38 | +```cpp |
| 39 | +#include "src/CThreadPool.h" |
| 40 | + |
| 41 | +using namespace CTP; |
| 42 | + |
| 43 | +float add_by_5(float i) { |
| 44 | + return i + 5.0f; |
| 45 | +} |
| 46 | + |
| 47 | +void tutorial() { |
| 48 | + UThreadPool tp; |
| 49 | + int i = 6, j = 3; |
| 50 | + auto r1 = tp.commit([i, j] { return i - j; }); |
| 51 | + std::future<float> r2 = tp.commit(std::bind(add_by_5, 8.5f)); |
| 52 | + |
| 53 | + std::cout << r1.get() << std::endl; |
| 54 | + std::cout << r2.get() << std::endl; |
| 55 | +} |
| 56 | +``` |
| 57 | +更多使用方法,请参考 `tutorial.cpp` 中的例子和文档中的内容。 |
| 58 | +
|
| 59 | +## 四. 推荐阅读 |
| 60 | +* [纯序员给你介绍图化框架的简单实现——线程池优化(一)](http://www.chunel.cn/archives/cgraph-threadpool-1-introduce) |
| 61 | +* [纯序员给你介绍图化框架的简单实现——线程池优化(二)](http://www.chunel.cn/archives/cgraph-threadpool-2-introduce) |
| 62 | +* [纯序员给你介绍图化框架的简单实现——线程池优化(三)](http://www.chunel.cn/archives/cgraph-threadpool-3-introduce) |
| 63 | +* [纯序员给你介绍图化框架的简单实现——线程池优化(四)](http://www.chunel.cn/archives/cgraph-threadpool-4-introduce) |
| 64 | +* [纯序员给你介绍图化框架的简单实现——线程池优化(五)](http://www.chunel.cn/archives/cgraph-threadpool-5-introduce) |
| 65 | +* [纯序员给你介绍图化框架的简单实现——线程池优化(六)](http://www.chunel.cn/archives/cgraph-threadpool-6-introduce) |
| 66 | +
|
| 67 | +## 五. 关联项目 |
| 68 | +* [CGraph : A simple C++ DAG framework](https://github.com/ChunelFeng/CGraph) |
| 69 | +
|
| 70 | +------------ |
| 71 | +#### 附录-1. 版本信息 |
| 72 | +[2022.10.05 - v1.0.0 - Chunel] |
| 73 | +* 提供线程池基本功能 |
| 74 | +* 提供对应的tutorial信息 |
| 75 | +
|
| 76 | +------------ |
| 77 | +#### 附录-2. 联系方式 |
| 78 | +* 微信: ChunelFeng |
| 79 | + |
| 80 | +* 源码: https://github.com/ChunelFeng/CThreadPool |
| 81 | +* 论坛: www.chunel.cn |
| 82 | +
|
| 83 | + |
0 commit comments