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

履歴 編集

function
<thread>

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

id get_id() const noexcept;

概要

関連付けられているスレッドのスレッド識別子を取得する。

戻り値

threadオブジェクトがスレッドに関連付けられている場合は、そのスレッドのスレッド識別子。そうでなければデフォルト構築されたthread::idオブジェクト。

例外

送出しない。

#include <thread>
#include <cassert>

int main()
{
  std::thread t1;
  assert( t1.get_id() == std::thread::id() );

  std::thread t2([]{ /*...*/ });
  assert( t2.get_id() != std::thread::id() );

  t2.join();
  return 0;
}

出力

バージョン

言語

  • C++11

処理系

参照