一、 包含内容
1 class thread 线程类
2 namesapce this_thread this_thread命名空间
二、线程类详解
1 成员类型
(1)native_handle_type 类型
native_handle_type是定义在线程类中的私有类型,用来维护线程在不同操作系统下的句柄值/线程id值。
(2)class id id类型
class id 是定义在线程类中的私有类型,用来维护一个native_handle_type类型的私有成员变量。
1 成员变量
native_handle_type _M_thread;
2 构造函数
id() noexcept; 默认构造函数
explicit id(native_handle_type __id) : _M_thread(__id) { } 初始化表构造函数
3 操作符重载函数
bool operator== (thread::id lhs, thread::id rhs) noexcept;
bool operator!= (thread::id lhs, thread::id rhs) noexcept;
bool operator< (thread::id lhs, thread::id rhs) noexcept;
bool operator<= (thread::id lhs, thread::id rhs) noexcept;
bool operator> (thread::id lhs, thread::id rhs) noexcept;
bool operator>= (thread::id lhs, thread::id rhs) noexcept;
操作符重载函数主要提供了thread::id的比较操作,并返回一个bool值。
template <class charT, class traits>
basic_ostream<chasrT, traits>& operator<< (basic_ostream<charT,traits>& os, thread::id id);
流操作符可以将一个id以文本的形式输出到标准的输出流中。
3 结论
class id作为class thread的私有成员函数被封装在线程类中,因此在调用线程类的过程中不需要使用者对id类的接口进行了解,因此对改类的功能做基本了解即可。
2 成员函数
1 构造函数
1 种类
thread() noexcept = default;
//默认构造函数
thread(thread&) = delete;
//拷贝构造函数被禁用
thread(thread&& __t) noexcept;
//移动构造函数可以使用
C++多线程库thread详解与使用

本文详细介绍了C++多线程库中的thread类,包括成员类型如类型和id类型,以及构造函数和操作符重载函数的用法。此外,还提到了this_thread命名空间的重要性和在多线程编程中的应用。
最低0.47元/天 解锁文章
541

被折叠的 条评论
为什么被折叠?



