std::this_thread::get_id
From cppreference.com
| ヘッダ <thread> で定義 |
||
| std::thread::id get_id() noexcept; |
(C++11以降) | |
現在のスレッドのIDを返します。
目次 |
[編集] パラメータ
(なし)
[編集] 戻り値
現在のスレッドのID。
[編集] 例
このコードを実行
#include <chrono> #include <iostream> #include <syncstream> #include <thread> using namespace std::chrono_literals; void foo() { std::thread::id this_id = std::this_thread::get_id(); std::osyncstream(std::cout) << "thread " << this_id << " sleeping...\n"; std::this_thread::sleep_for(500ms); } int main() { std::jthread t1{foo}; std::jthread t2{foo}; }
実行結果の例
thread 140113018054400 sleeping... thread 140113009661696 sleeping...
[編集] 関連項目
| スレッドのIDを返す ( std::threadの公開メンバ関数) | |
| thrd_currentのCドキュメント
| |