我正在通过对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开始?