# cwj_thread_pool **Repository Path**: Yi_F/threadpool ## Basic Information - **Project Name**: cwj_thread_pool - **Description**: 一个基于C++11带有返回值的线程池库实现 - **Primary Language**: C++ - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2022-10-27 - **Last Updated**: 2023-04-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: 线程池, Cpp ## README ## cwj_threahpool 线程池 该线程是基于C++11实现的高性能多线程复用池 该线程池分为两种模式: - 一种为固定连接模式 - 一种是动态扩容连接模式,当任务数目超过可用线程数且任务延迟超过指定时间时就会动态新增线程,直到到达最大指定数或是线程空闲。当任务空闲超过指定时长时,会动态缩容,直到到达默认数目 `subtask_函数`返回值:`Result`其会根据提交任务的类型而返回不同的类型 其中,有两大类,即`Result`和`Result<非void>`,前者无get函数,后者可以通过get函数取值(类模板特化实现) ## 安装与使用 [安装与使用教程](doc/tutorials.md) ## 示例 ### 代码 ```c++ #include "../src/threadpool.h" #include #include using namespace std; using namespace CWJ; using ULL = unsigned long long; void runTask(ULL st,ULL ed){ ULL res = 0; for(int i=st;i res = "<< res << std::endl; } ULL runTaskHasRes(ULL st,ULL ed){ ULL res = 0; for(int i=st;i>> res_list; for(int i=0;i<100;i++) { tp.submitTask_(runTask, 1, 1e6); res_list.push_back((tp.submitTask_(runTaskHasRes,1,1e6))); } std::cout<<" end submit "<在调用get函数后, 会阻塞直到对应的任务被完成 ULL res = 0; for(const auto& a : res_list){ res += a->get(); } std::cout<<"main: res:"<