代码拉取完成,页面将自动刷新
#pragma once
#include <pthread.h>
#include <list>
#include "locker.h"
// 文件名称:threadpool.h
// 类:threadpool
// 功能:线程池
// 作者:TRF
// 线程池类,模板类,方便复用
template <typename T>
class Threadpool
{
private:
int m_thread_num; // 线程数量
pthread_t *m_threads; // 线程池数组,大小为m_thread_num
int m_max_requeats; // 请求队列中最多允许的,等待处理的请求数量
std::list<T *> m_workqueue; // 请求队列,存放待处理的请求
Locker m_queuelocker; // 互斥锁
Semaphore m_queuestat; // 信号量,用来判断是否有任务需要处理
bool m_stop; // 是否结束线程
static void *worker(void *arg); // 线程函数,static只能在本文件中定义,不能放在类外面
void run(); // 运行线程池
public:
Threadpool(int thread_num = 8, int max_requeats = 100000);
~Threadpool();
bool append(T *request); // 添加任务到请求队列
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。