-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThreadPool.h
38 lines (32 loc) · 1.02 KB
/
ThreadPool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef THREADPOOL_H
#define THREADPOOL_H
#include <pthread.h>
/*
线程池类
功能:
创建不超过最大线程数量的线程;
取出并处理请求;
添加请求;
关闭线程池;
*/
template<typename T>
class ThreadPool
{
private:
std::list<T *> Request_List; // 思考Request_List和ThreadID_List选择这样的数据结构的原因
std::vector<pthread_t> ThreadID_List; // pthread_t是线程的ID类型
pthread_mutex_t mutex;
static unsigned int Max_Requests;
int Thread_Num;
static const int Max_Thread_Num = 16; // 作为特例,有序型的const静态数据成员可以在类体中用一常量值初始化
bool Server_IsOn; //?应放在一个更合理的地方
static bool worker();
void run();
public:
ThreadPool(int Thread_Num);
~ThreadPool();
bool append(T *request);
void shutDown();
}
unsigned int ThreadPool::Max_Requests = 65536;
#endif