C++11 thread::id 表示无线程的特殊值

标签 c++ multithreading c++11 stdthread

man page指出

Instances of this class may also hold the special distinct value that does not represent any thread.

但是我到处都找不到这个特殊值是什么或者它是在哪里定义的(在 中查找)。有什么想法吗?

最佳答案

默认构造函数是这样记录的:

Default-constructs a new thread identifier. The identifier does not represent a thread.

因此,如果您想要非线程标识符,只需默认构造一个 id。默认构造的值可以与任何线程 id 进行比较,以检查后者是否不是线程。

关于C++11 thread::id 表示无线程的特殊值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25973926/

相关文章:

c# - 在内存中渲染 Livecharts 图表并另存为图像

c# - 这种对 Monitor.Wait/Pulse 的使用是否存在竞争条件?

c++ - 为什么enable_shared_from_this必须公开继承?

c++ - 如何在不使用标准算法的情况下在排序 vector 中添加 c 元素?

c++ - 使用带有 remove_if 的删除

c++ - 将两个不同大小的2d数组相乘

c - 如何在 FreeBSD/Mac OS X 中从 Mutex 对象获取拥有的线程 ID

c++ - 如何在文件中写入动态分配的 2D 'array'?

c++ - 如何创建 C++ 模板以最佳方式传递值?

c++ - 复制构造函数中的指针赋值