1、获取当前线程的线程ID
2、获取声明的线程变量的线程ID
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <thread>
#include <windows.h>
using namespace std;
void hello()
{
Sleep(2000);
cout << "hello world!" << endl;
}
int main()
{
thread t(hello);
thread::id thread_id = t.get_id(); // 获取特定线程的id
thread::id this_thread_id = this_thread::get_id(); // 获取本线程的id
cout << "thread id = " << thread_id << endl;
cout << "this thread id = " << this_thread_id << endl;
t.join();
return 0;
}
谢谢阅读