在创建一个thread实例以后,提供了以下几个函数接口:
detach();//detach therad
意思是在构造thread之后,可以该线程与实例分离,然后即使在该变量被收回之后仍然能执行该线程
void detach()
{ // detach thread
if (!joinable())
_Throw_Cpp_error(_INVALID_ARGUMENT);
_Thrd_detachX(_Thr);
_Thr_set_null(_Thr);
}
get_id(); return id for this thread
inline thread::id thread::get_id() const _NOEXCEPT
{ // return id for this thread
return (id(*this));
}
join();等待前一个线程执行完之后才执行
inline void thread::join()
{ // join thread
if (!joinable())
_Throw_Cpp_error(_INVALID_ARGUMENT);
if (_Thr_is_null(_Thr))
_Throw_Cpp_error(_INVALID_ARGUMENT);
if (get_id() == _STD this_thread::get_id())
_Throw_Cpp_error(_RESOURCE_DEADLOCK_WOULD_OCCUR);
if (_Thrd_join(_Thr, 0) != _Thrd_success)
_Throw_Cpp_error(_NO_SUCH_PROCESS);
_Thr_set_nul