std::thread::id std::thread::get_id() を呼ぶ
void foo( ostringstream &os ) {
os << "foo(): " << this_thread::get_id() << endl;
}
void bar( ostringstream &os ) {
os << "bar(): " << this_thread::get_id() << endl;
}
ostringstream os_foo;
ostringstream os_bar;
thread th1( foo(), ref( os_foo ) );
thread th2( bar(), ref( os_bar ) );
// それぞれの thread ID を得る
thread::id id1 = th1.get_id();
thread::id id2 = th2.get_id();
thread::id id3 = this_thread::get_id();
assert( id1 != is2 );
assert( id1 != is3 );
assert( id2 != is3 );
th1.join();
th2.join();
cout << os_foo.str();
cout << os_bar.str();
cout << "main thread : " << this_thread::get_id() << endl;