名前空間
変種
操作

std::jthread::get_id

提供: cppreference.com
< cpp‎ | thread‎ | jthread
 
 
スレッドサポートライブラリ
スレッド
(C++11)
(C++20)
(C++20)
this_thread 名前空間
(C++11)
(C++11)
(C++11)
相互排他
(C++11)
汎用ロック管理
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
条件変数
(C++11)
セマフォ
ラッチとバリア
(C++20)
(C++20)
フューチャー
(C++11)
(C++11)
(C++11)
(C++11)
 
 
[[nodiscard]] std::jthread::id get_id() const noexcept;
(C++20以上)

*this に紐付いたスレッドを識別する std::jthread::id の値を返します。

目次

[編集] 引数

(なし)

[編集] 戻り値

*this に紐付いたスレッドを識別する std::jthread::id 型の値。 紐付いたスレッドがない場合はデフォルト構築された std::jthread::id が返されます。

[編集]

#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のパブリックメンバクラス) [edit]
スレッドが合流可能かどうか、すなわち潜在的に並列文脈で実行中かどうか調べます
(パブリックメンバ関数) [edit]