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