std::thread::get_id
提供: cppreference.com
std::thread::id get_id() const noexcept; |
(C++11以上) | |
*this に紐付いたスレッドを識別する std::thread::id の値を返します。
引数
(なし)
戻り値
*this に紐付いたスレッドを識別する std::thread::id 型の値。 紐付いたスレッドがない場合はデフォルト構築された std::thread::id が返されます。
例
Run this code
#include <iostream>
#include <thread>
#include <chrono>
void foo()
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
int main()
{
std::thread t1(foo);
std::thread::id t1_id = t1.get_id();
std::thread t2(foo);
std::thread::id t2_id = t2.get_id();
std::cout << "t1's id: " << t1_id << '\n';
std::cout << "t2's id: " << t2_id << '\n';
t1.join();
t2.join();
}
出力例:
t1's id: 0x35a7210f
t2's id: 0x35a311c4
関連項目
| スレッドの id を表します (パブリックメンバクラス) | |
| スレッドが合流可能かどうか、すなわち潜在的に並列文脈で実行中かどうか調べます (パブリックメンバ関数) |