线程id是用于标识当前线程的,所以需要获取当前线程id,以便程序处理一些问题。
#include<iostream>
#include<thread>
using namespace std;
void f()
{
std::thread::id tid = std::this_thread::get_id();
cout << "f id=" << tid << endl;
}
int main(int argc, int * argv[])
{
thread t(f);
t.join();
std::thread::id tid = std::this_thread::get_id();
cout << "main id=" << tid << endl;
system("pause");
}
结果如下: