线程id是用于标识当前线程的,因此须要获取当前线程id,以便程序处理一些问题。ios
#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"); }
结果以下:this