日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

stdthread(1)thread概述

發(fā)布時(shí)間:2025/3/21 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 stdthread(1)thread概述 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1. thread類主要方法

不支持 CopyConstructible or CopyAssignable,
支持 MoveConstructible and MoveAssignable.

  • 構(gòu)造函數(shù)
    默認(rèn)構(gòu)造函數(shù):構(gòu)造一個(gè)任何線程不執(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,返回一個(gè)類型為 std::thread::id 的對象。

  • swap 交換兩個(gè)線程對象所代表的底層句柄(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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。