最終更新日時(UTC):
が更新

履歴 編集

class
<thread>

std::thread::id(C++11)

namespace std {
  class thread::id {
  public:
    id() noexcept;
  };

  bool operator==(thread::id x, thread::id y) noexcept;
  bool operator!=(thread::id x, thread::id y) noexcept;
  bool operator<(thread::id x, thread::id y) noexcept;
  bool operator<=(thread::id x, thread::id y) noexcept;
  bool operator>(thread::id x, thread::id y) noexcept;
  bool operator>=(thread::id x, thread::id y) noexcept;

  template<class CharT, class Traits>
  std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& out, thread::id id);

  template <class T> struct hash;
  template <> struct hash<thread::id>;
}

概要

スレッド識別子。trivially copyable class。

実行のスレッドに対して一意なthread::idが対応づけられる。デフォルト構築されたthread::idはいかなるスレッドとも対応付けられない(ポインタ型におけるnullptrのようなもの)。

終了したスレッドを表す識別子の値は、再利用される可能性がある。

メンバ関数

名前 説明 対応バージョン
id() noexcept デフォルトコンストラクタ。いかなるスレッドも指さない識別子を生成する。 C++11

比較演算子

名前 説明 対応バージョン
operator== 等値比較 C++11
operator!= 非等値比較 (C++20からoperator==により使用可能) C++11
operator< 左辺が右辺より小さいかの判定を行う (C++20からoperator<=>により使用可能) C++11
operator<= 左辺が右辺以下かの判定を行う (C++20からoperator<=>により使用可能) C++11
operator> 左辺が右辺より大きいかの判定を行う (C++20からoperator<=>により使用可能) C++11
operator>= 左辺が右辺以上かの判定を行う (C++20からoperator<=>により使用可能) C++11
strong_ordering operator<=>(thread::id x, thread::id y) noexcept; 三方比較 C++20

ストリーム出力

名前 説明 対応バージョン
operator<< thread::idのストリーム出力。 フォーマットは未規定だが、他の識別子と異なることがわかる表現となる。 C++11

hashサポート

名前 説明 対応バージョン
hash thread::idでの特殊化 (class template) C++11

#include <iostream>
#include <thread>

int main()
{
  const std::thread::id main_tid = std::this_thread::get_id();
  std::cout << "main=" << main_tid << std::endl;
  return 0;
}

出力例

main=824a30

バージョン

言語

  • C++11

処理系

参照