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...
参见
|
返回线程的
标识符
(
std::thread
的公开成员函数)
|
|
|
C 文档
关于
thrd_current
|
|