首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::thread::get_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

二次

代码语言:javascript
复制
#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();
}

二次

可能的产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com