std::this_thread:: get_id
From cppreference.net
C++
Concurrency support library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<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
の公開メンバ関数)
|
|
|
Cドキュメント
for
thrd_current
|
|