1 Star 0 Fork 1

cyx20080216/ThreadPool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
threadpool.h 831 Bytes
一键复制 编辑 原始数据 按行查看 历史
cyx20080216 提交于 2021-07-19 10:56 . ThreadPool
#include<thread>
#include<mutex>
#include<list>
#include<queue>
#include<functional>
class ThreadPool
{
public:
ThreadPool(const unsigned &corePoolSize,const unsigned maxPoolSize,const unsigned &keepAliveTime,const unsigned &maxQueueSize,const std::function<void(const std::function<void(void)>&)> &handler);
~ThreadPool();
bool execute(const std::function<void(void)> &work);
private:
const unsigned corePoolSize;
const unsigned maxPoolSize;
const unsigned keepAliveTime;
const unsigned maxQueueSize;
unsigned workCount;
std::mutex workCountLock;
const std::function<void(const std::function<void(void)>&)> handler;
std::queue<std::function<void(void)> > workQueue;
std::mutex workQueueLock;
std::list<std::thread*> threadList;
std::mutex threadListLock;
bool shutdown;
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cyx20080216/ThreadPool.git
[email protected]:cyx20080216/ThreadPool.git
cyx20080216
ThreadPool
ThreadPool
main

搜索帮助