std::this_thread::get_id
提供: cppreference.com
ヘッダ <thread> で定義
|
||
std::thread::id get_id() noexcept; |
(C++11以上) | |
現在のスレッドの id を返します。
目次 |
[編集] 引数
(なし)
[編集] 戻り値
現在のスレッドの id。
[編集] 例
Run this code
#include <iostream> #include <thread> #include <chrono> #include <mutex> std::mutex g_display_mutex; void foo() { std::thread::id this_id = std::this_thread::get_id(); g_display_mutex.lock(); std::cout << "thread " << this_id << " sleeping...\n"; g_display_mutex.unlock(); std::this_thread::sleep_for(std::chrono::seconds(1)); } int main() { std::thread t1(foo); std::thread t2(foo); t1.join(); t2.join(); }
出力例:
thread 0x2384b312 sleeping... thread 0x228a10fc sleeping...
[編集] 関連項目
スレッドの id を返します ( std::thread のパブリックメンバ関数)
| |
thrd_current の C言語リファレンス
|