我正在通過對C++ 0x(C++ 11)中存在的多線程的新支持。在C++中的線程ID行爲11
因此,每個線程都有一個類型爲std :: thread:id的唯一標識符。
考慮下面的示例程序:
void hello_world()
{
std::cout<<"hello_world \n";
}
int main()
{
std::cout<<"Main thread id is "<<std::this_thread::get_id()<<"\n";
std::thread t(hello_world);
std::cout<<"Child thread id is ";
std::cout<<t.get_id()<<"\n";
t.join();
}
我得到了一個樣本輸出如下:
主線程ID爲140502917359424
子線程ID爲140502900623104
程序hello_world
主要的線程ID我的示例輸出中的線程大於子線程ID。
線程ID是否完全獨立於其啓動時間?
如果不是:有沒有一種方法來區分線程T1是否早於線程T2從線程ID開始?