fastdo  0.5.12
winux::Thread类 参考

线程 更多...

#include <threads.hpp>

Public 类型

typedef void *(* ThreadFuncPtr) (void *param)
 线程处理函数指针类型 更多...
 

Public 成员函数

 Thread (bool isStartup=false)
 构造函数1 更多...
 
template<typename _Fx , typename... _ArgType>
 Thread (bool isStartup, _Fx routine, _ArgType &&...arg)
 构造函数2 更多...
 
virtual ~Thread ()
 析构函数 更多...
 
 Thread (Thread &&other)
 移动构造 更多...
 
Threadoperator= (Thread &&other)
 移动赋值 更多...
 
int startup ()
 实际创建一个线程 更多...
 
template<typename _Fx , typename... _ArgType>
int startup (_Fx routine, _ArgType &&...arg)
 实际创建一个线程,提供你自己的处理例程 更多...
 
int startupEx (ThreadFuncPtr startRoutine, void *param)
 实际创建一个线程,提供你自己的处理函数 更多...
 
void * joined ()
 被调用者线程连接 更多...
 
int detach ()
 使线程分离 更多...
 
ThreadAttrattr ()
 设置线程属性对象,下次startup()时生效 更多...
 
template<typename _Fx , typename... _ArgType>
ThreadsetRunable (_Fx routine, _ArgType &&...arg)
 设置Runable,run()默认会调用它 更多...
 
ThreadsetDeleter (SimpleDeleterContext *deleter=NULL)
 设置删除器场景以便默认线程函数删除Thread对象自己 更多...
 
ThreadsetDefaultDeleter ()
 设置默认删除器场景以便默认线程函数删除Thread对象自己 更多...
 
template<typename _Dt >
ThreadsetCustomDeleter (_Dt fn)
 设置自定义删除器场景以便默认线程函数删除Thread对象自己 更多...
 
void * getExitVal () const
 取得退出值 更多...
 
ThreadsetExitVal (void *exitVal)
 设置退出值,可在run()中调用 更多...
 
ThreadId get () const
 线程Id 更多...
 

静态 Public 成员函数

static ThreadId Self ()
 得到调用者线程的ThreadId 更多...
 
static void Exit (void *exitVal=NULL)
 调用者线程退出 更多...
 
static void * Join (Thread &otherThread)
 调用者线程连接指定其他线程 更多...
 

Protected 成员函数

virtual void run ()
 线程处理函数,默认调用内部的Runable,派生线程类可重写此函数 更多...
 

友元

class ThreadGroup
 

详细描述

线程

在文件 threads.hpp89 行定义.

成员类型定义说明

typedef void*(* winux::Thread::ThreadFuncPtr) (void *param)

线程处理函数指针类型

在文件 threads.hpp94 行定义.

构造及析构函数说明

winux::Thread::Thread ( bool  isStartup = false)
inlineexplicit

构造函数1

isStartup=false时不立即创建线程,用户手动调用startup()函数创建线程 isStartup=true时立即创建一个线程,以run()作为线程处理函数,用户需要派生Thread类重写run()函数以定义自己的处理

在文件 threads.hpp118 行定义.

template<typename _Fx , typename... _ArgType>
winux::Thread::Thread ( bool  isStartup,
_Fx  routine,
_ArgType &&...  arg 
)
inlineexplicit

构造函数2

立即创建一个线程,以routine作为线程处理例程

在文件 threads.hpp127 行定义.

virtual winux::Thread::~Thread ( )
inlinevirtual

析构函数

在文件 threads.hpp134 行定义.

winux::Thread::Thread ( Thread &&  other)

移动构造

成员函数说明

ThreadAttr& winux::Thread::attr ( )

设置线程属性对象,下次startup()时生效

int winux::Thread::detach ( )

使线程分离

一个可连接线程启动后必须调用joined()来等待运行完毕,内部资源才能正确释放。调用此detach()方法后不能再调用joined()方法。 此时,线程函数若有访问Thread对象的数据,必须保证线程运行结束前Thread对象的存在,但是因为没有了joined()方法的同步,你需要自己设计代码来保证对象不会提前释放。 设置删除器可以一定程度上简化代码,如果Thread对象设置了删除器,那默认的线程函数处理时会在运行结束前调用删除器释放Thread对象。 若你调用了startupEx()提供自己的线程处理函数,那就需要自己设计代码来保证Thread对象不会提前释放。

static void winux::Thread::Exit ( void *  exitVal = NULL)
static

调用者线程退出

ThreadId winux::Thread::get ( ) const
inline

线程Id

在文件 threads.hpp206 行定义.

void* winux::Thread::getExitVal ( ) const
inline

取得退出值

在文件 threads.hpp197 行定义.

static void* winux::Thread::Join ( Thread otherThread)
static

调用者线程连接指定其他线程

退出状态由返回值或者otherThread.getExitVal()取得

void* winux::Thread::joined ( )

被调用者线程连接

Thread& winux::Thread::operator= ( Thread &&  other)

移动赋值

virtual void winux::Thread::run ( )
protectedvirtual

线程处理函数,默认调用内部的Runable,派生线程类可重写此函数

static ThreadId winux::Thread::Self ( )
static

得到调用者线程的ThreadId

template<typename _Dt >
Thread& winux::Thread::setCustomDeleter ( _Dt  fn)
inline

设置自定义删除器场景以便默认线程函数删除Thread对象自己

在文件 threads.hpp194 行定义.

Thread& winux::Thread::setDefaultDeleter ( )
inline

设置默认删除器场景以便默认线程函数删除Thread对象自己

在文件 threads.hpp191 行定义.

Thread& winux::Thread::setDeleter ( SimpleDeleterContext deleter = NULL)
inline

设置删除器场景以便默认线程函数删除Thread对象自己

在文件 threads.hpp185 行定义.

Thread& winux::Thread::setExitVal ( void *  exitVal)
inline

设置退出值,可在run()中调用

在文件 threads.hpp199 行定义.

template<typename _Fx , typename... _ArgType>
Thread& winux::Thread::setRunable ( _Fx  routine,
_ArgType &&...  arg 
)
inline

设置Runable,run()默认会调用它

在文件 threads.hpp178 行定义.

int winux::Thread::startup ( )

实际创建一个线程

以run()作为线程处理,用户可继承Thread类重写run()方法以定义自己的处理;也可以setRunable()设置一个可运行对象作为线程处理例程 startup()会设置_isRunning为true,在默认的线程处理函数里,调用完run()方法后设置_isRunning为false

template<typename _Fx , typename... _ArgType>
int winux::Thread::startup ( _Fx  routine,
_ArgType &&...  arg 
)
inline

实际创建一个线程,提供你自己的处理例程

在文件 threads.hpp150 行定义.

int winux::Thread::startupEx ( ThreadFuncPtr  startRoutine,
void *  param 
)

实际创建一个线程,提供你自己的处理函数

友元及相关函数文档

friend class ThreadGroup
friend

在文件 threads.hpp224 行定义.


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