std::this_thread::get_id
來自 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 的公開成員函式) | |
C 文件 關於 thrd_current
|