- C 标准库
- C 标准库
- C++ 标准库
- C++ 库 - 主页
- C++ 库 - <fstream>
- C++ 库 - <iomanip>
- C++ 库 - <ios>
- C++ 库 - <iosfwd>
- C++ 库 - <iostream>
- C++ 库 - <istream>
- C++ 库 - <ostream>
- C++ 库 - <sstream>
- C++ 库 - <streambuf>
- C++ 库 - <原子>
- C++ 库 - <复杂>
- C++ 库 - <异常>
- C++ 库 - <功能>
- C++ 库 - <限制>
- C++ 库 - <语言环境>
- C++ 库 - <内存>
- C++ 库 - <新>
- C++ 库 - <数字>
- C++ 库 - <正则表达式>
- C++ 库 - <stdexcept>
- C++ 库 - <字符串>
- C++ 库 - <线程>
- C++ 库 - <元组>
- C++ 库 - <类型信息>
- C++ 库 - <实用程序>
- C++ 库 - <valarray>
C++ 线程库 - 函数 get_id
描述
它返回线程 ID。
宣言
以下是 std::thread::get_id 函数的声明。
id get_id() const noexcept;
C++11
id get_id() const noexcept;
参数
没有任何
返回值
它返回线程 ID。
例外情况
无抛出保证- 永远不会抛出异常。
数据竞赛
对象被访问。
例子
在下面的 std::thread::get_id 示例中。
#include <iostream>
#include <thread>
#include <chrono>
void foo() {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
int main() {
std::thread sample(foo);
std::thread::id sample_id = sample.get_id();
std::thread sample2(foo);
std::thread::id sample2_id = sample2.get_id();
std::cout << "sample's id: " << sample_id << '\n';
std::cout << "sample2's id: " << sample2_id << '\n';
sample.join();
sample2.join();
}
输出应该是这样的 -
sample's id: 139887397730048 sample2's id: 139887389337344
线程.htm