[C++ Multithreading Series] [3] Get the current thread id

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:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325444463&siteId=291194637