fastdo  0.5.12
winux::ThreadPool类 参考

线程池,创建一组线程等待着从任务队列中获取任务执行 更多...

#include <threads.hpp>

Public 类型

enum  ThreadPoolMode { modeWaitKeep, modeWaitTimeRePost }
 

Public 成员函数

 ThreadPool (int threadCount=4, ThreadPoolMode mode=modeWaitKeep, double durationSec=0.1)
 构造函数1 更多...
 
virtual ~ThreadPool ()
 
template<typename _Fx , typename... _ArgType>
Task< typename FuncTraits< _Fx >::ReturnType > task (_Fx fn, _ArgType &&...arg)
 创建一个新任务 更多...
 
void stop ()
 主动停止线程池运行 更多...
 
bool wait (double sec=-1)
 wait(sec>0)等待一定的时间长用于等待任务运行。当调用stop()后,wait(sec<0)等待线程组线程全部正常退出 更多...
 
void whenEmptyStopAndWait ()
 当任务队列为空,就停止线程池运行,并等待线程组线程正常退出 更多...
 
size_t getTaskCount () const
 队列里的任务数 更多...
 
double getDurationSec () const
 等待的时间(秒) 更多...
 

友元

struct TaskCtx
 
template<typename _Ty0 >
class Task
 

详细描述

线程池,创建一组线程等待着从任务队列中获取任务执行

在文件 threads.hpp619 行定义.

成员枚举类型说明

枚举值
modeWaitKeep 

一直等待上一个任务

modeWaitTimeRePost 

等待一定时间后重投

在文件 threads.hpp623 行定义.

构造及析构函数说明

winux::ThreadPool::ThreadPool ( int  threadCount = 4,
ThreadPoolMode  mode = modeWaitKeep,
double  durationSec = 0.1 
)
inlineexplicit

构造函数1

参数
threadCount启动的线程数量
mode线程池模式
durationSec等待的时间

在文件 threads.hpp633 行定义.

virtual winux::ThreadPool::~ThreadPool ( )
inlinevirtual

在文件 threads.hpp664 行定义.

成员函数说明

double winux::ThreadPool::getDurationSec ( ) const
inline

等待的时间(秒)

在文件 threads.hpp711 行定义.

size_t winux::ThreadPool::getTaskCount ( ) const
inline

队列里的任务数

在文件 threads.hpp704 行定义.

void winux::ThreadPool::stop ( )
inline

主动停止线程池运行

在文件 threads.hpp677 行定义.

template<typename _Fx , typename... _ArgType>
Task<typename FuncTraits<_Fx>::ReturnType> winux::ThreadPool::task ( _Fx  fn,
_ArgType &&...  arg 
)
inline

创建一个新任务

在文件 threads.hpp671 行定义.

bool winux::ThreadPool::wait ( double  sec = -1)
inline

wait(sec>0)等待一定的时间长用于等待任务运行。当调用stop()后,wait(sec<0)等待线程组线程全部正常退出

在文件 threads.hpp685 行定义.

void winux::ThreadPool::whenEmptyStopAndWait ( )
inline

当任务队列为空,就停止线程池运行,并等待线程组线程正常退出

在文件 threads.hpp691 行定义.

友元及相关函数文档

template<typename _Ty0 >
friend class Task
friend

在文件 threads.hpp732 行定义.

friend struct TaskCtx
friend

在文件 threads.hpp730 行定义.


该类的文档由以下文件生成: