std::thread::get_id
STD::线程::获取[医]ID
std::thread::id get_id() const; | | (since C++11) |
---|
返回值为std::thread::id
标识与*this
...
参数
%280%29
返回值
类型值std::thread::id
标识与*this
如果没有与线程相关的线程,则默认构造std::thread::id
会被归还。
例外
noexcept
规格:
noexcept
例
二次
#include <iostream>
#include <thread>
#include <chrono>
void foo()
{
std::this_thread::sleep_for(std::chrono::seconds(1)
}
int main()
{
std::thread t1(foo
std::thread::id t1_id = t1.get_id(
std::thread t2(foo
std::thread::id t2_id = t2.get_id(
std::cout << "t1's id: " << t1_id << '\n';
std::cout << "t2's id: " << t2_id << '\n';
t1.join(
t2.join(
}
二次
可能的产出:
二次
t1's id: 0x35a7210f
t2's id: 0x35a311c4
二次
另见
id | represents the id of a thread (public member class) |
---|---|
joinable | checks whether the thread is joinable, i.e. potentially running in parallel context (public member function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。