C++11多线程之std::thread

先看thread的定义:

类 std::thread:

class thread {
 public:
    // 类型:
    class id;//线程的id
    typedef /*implementation-defined*/ native_handle_type;
 
    // 构造/复制/销毁:
    thread() noexcept;//构造函数
    template <class F, class ...Args> explicit thread(F&& f, Args&&... args);
    ~thread();//析构函数
    thread(const thread&) = delete;
    thread(thread&&) noexcept;
    thread& operator=(const thread&) = delete;
    thread& operator=(thread&&) noexcept;
 
    // 成员:
    void swap(thread&) noexcept;
    bool joinable() const noexcept;
    void join();
    void detach();
    id get_id() const noexcept;
    native_handle_type native_handle();
 
    // 静态成员:
    static unsigned hardware_concurrency() noexcept;
};

类 std::thread::id

class thread::id {
 public:
    id() noexcept;
};

成员类型:

native_handle_type 实现定义

成员类:

id 表示线程的id

成员函数:

构造函数    构造新的thread对象

析构函数    析构thread对象,必须合并或分离底层线程

operator=    移动thread对象

观察器:

joinable    检查线程是否可合并,即潜在的运行于平行环境中

get_id       返回线程的id

native_handle    返回底层实现定义的线程句柄

hardware_concurrency[静态]    返回实现支持的并发线程数

操作:

join        等待线程完成其执行

detach    容许线程从线程句柄独立开来执行

swap    交换两个thread对象

非成员函数:

std::swap     特化std::swap算法 (函数模板)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值