線程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