【C++多线程系列】【三】获取当前线程id

线程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");
}

结果如下:

猜你喜欢

转载自my.oschina.net/u/3800567/blog/1798157