首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::thread

Defined in header <thread>

?

?

class thread;

?

(since C++11)

全班thread代表单线程执行%28http://en.wikipara.com/wiki/Thread_%28计算%29%29线程允许并发执行多个函数。

线程在构造关联的线程对象%28时立即开始执行,所有OS调度延迟都会延迟到%29,从顶层函数开始,作为构造参数忽略顶层函数的返回值,如果它通过抛出异常终止,std::terminate叫做。顶层函数可以通过以下方式将其返回值或异常传递给调用方。std::promise或者修改可能需要同步的共享变量%28,请参见std::mutexstd::atomic29%。

std::thread对象也可能处于不表示任何线程%28的状态。detach,或join%29,并且执行线程可能与任何thread对象%28之后detach29%。

不二std::thread对象可以表示相同的执行线程;std::thread不是CopyConstructibleCopyAssignable,尽管它是MoveConstructibleMoveAssignable...

成员类型

Member type

Definition

native_handle_type

implementation-defined

成员类

id

represents the id of a thread (public member class)

成员函数

(constructor)

constructs new thread object (public member function)

(destructor)

destructs the thread object, underlying thread must be joined or detached (public member function)

operator=

moves the thread object (public member function)

观察员

Joinable检查线程是否可连接,即可能在并行上下文%28公共成员函数%29中运行。

弄到[医]ID%28C++11%29返回线程%28公共成员函数%29的id

土生土长[医]句柄返回底层实现定义的线程句柄%28公共成员函数%29

硬件[医]并发性静态返回实现%28公共静态成员函数%29支持的并发线程数。

操作

连接等待线程完成其执行%28公共成员函数%29

Deach允许线程独立于线程句柄%28公共成员函数%29执行。

交换交换两个线程对象%28公共成员函数%29

非会员职能

std::swap(std::thread) (C++11)

specializes the std::swap algorithm (function template)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com