名前空間
変種

std::thread::get_id

提供: cppreference.com
 
 
スレッドサポートライブラリ
スレッド
(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)
 
 
<tbody> </tbody>
std::thread::id get_id() const noexcept;
(C++11以上)

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

引数

(なし)

戻り値

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

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