stdthread(1)thread概述
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                stdthread(1)thread概述
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                1. thread類主要方法
不支持 CopyConstructible or CopyAssignable,
 支持 MoveConstructible and MoveAssignable.
- 構(gòu)造函數(shù)
 默認(rèn)構(gòu)造函數(shù):構(gòu)造一個任何線程不執(zhí)行的線程對象。
 thread() noexcept;
初始化函數(shù):
 template <class Fn, class… Args> explicit thread (Fn&& fn, Args&&… args);
拷貝構(gòu)造函數(shù)是被禁用的:thread (const thread&) = delete;
-  join MainThread 被阻塞,直到child thread 線程執(zhí)行完畢。 
-  joinable 是否是join 
-  detach 分離線程對象 
-  get_id 獲取線程 ID,返回一個類型為 std::thread::id 的對象。 
-  swap 交換兩個線程對象所代表的底層句柄(underlying handles)。 
-  native_handle 
-  hardware_concurrency [static] 
-  析構(gòu) ~thread() 
 {
 if (joinable())
 std::terminate();
 }
-  operator= 
1.1
class thread{public:thread() noexcept = default;template<typename _Callable, typename... _Args,typename = _Require<__not_same<_Callable>>>explicitthread(_Callable&& __f, _Args&&... __args){static_assert( __is_invocable<typename decay<_Callable>::type,typename decay<_Args>::type...>::value,"std::thread arguments must be invocable after conversion to rvalues");~thread(){if (joinable())std::terminate();}thread(const thread&) = delete;thread(thread&& __t) noexcept{ swap(__t); }thread& operator=(const thread&) = delete;thread& operator=(thread&& __t) noexcept{if (joinable())std::terminate();swap(__t);return *this;}voidswap(thread& __t) noexcept{ std::swap(_M_id, __t._M_id); }booljoinable() const noexcept{ return !(_M_id == id()); }voidjoin();voiddetach();thread::idget_id() const noexcept{ return _M_id; }// Returns a value that hints at the number of hardware thread contexts.static unsigned inthardware_concurrency() noexcept; ... }inline void thread::join() {if (this_thread::get_id() == get_id())boost::throw_exception(thread_resource_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost thread: trying joining itself"));BOOST_THREAD_VERIFY_PRECONDITION( join_noexcept(),thread_resource_error(static_cast<int>(system::errc::invalid_argument), "boost thread: thread not joinable"));}總結(jié)
以上是生活随笔為你收集整理的stdthread(1)thread概述的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: STL源代码分析(ch2 内存分配)jj
- 下一篇: stdthread(2)创建
