C++11将线程引入了标准模板库,thread类定义在“thread”头文件中,thread类是对pthread库函数的封装。
构造函数
- thread() noexcept;
- template <class Fn, class… Args>
explicit thread (Fn&& fn, Args&&… args); - thread (const thread&) = delete;
- thread (thread&& x) noexcept;
thread的拷贝构造函数是被delete
创建一个thread对象可以使用以下方法
- 函数地址
- lambda表达式
- 仿函数
成员函数
- get_id 返回线程id (public member function )
- joinable Check if joinable (public member function )
- join 主线程阻塞,等待线程执行完成 (public member function )
- detach 分离线程 (public member function )
- swap 交换线程 (public member function )
- native_handle Get native handle (public member function )
静态成员函数
- hardware_concurrency [static] 返回硬件的CPU核数 (public static member function )