The thread id is used to identify the current thread, so it is necessary to obtain the current thread id so that the program can handle some problems.
#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");
}
The result is as follows: