線程識別類型是std::thread::id。
檢索方式:
- 通過調(diào)用std::thread對象的成員函數(shù)get_id()來直接獲取。如果 std::thread 對象沒有與任何執(zhí)行線程相關(guān)聯(lián), 那么 get_id() 將返回 std::thread::type 默認構(gòu)造值, 這個值表示“沒有線程”。
- 在當前線程中,調(diào)用std::this_thread::get_id()也可以獲得線程表示。
std::thread::id 對象可以自由的拷貝和對比;標識符就可以復(fù)用
std::thread::id類型對象提供相當豐富的對比操作,允許成員將其當做為容器的兼職,或做排序,或做其他方式的比較。
std::thread::id master_thread;
void some_core_part_of_algorithm()
{
if(std::this_thread::get_id()==master_thread)
{
do_master_thread_work();
}
do_common_work();
}