在线文档教程
C++
线程支持 | Thread support

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

二次

另见

idrepresents the id of a thread (public member class)
joinablechecks whether the thread is joinable, i.e. potentially running in parallel context (public member function)

© cppreference.com

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

http://en.cppreference.com/w/cpp/线程/线程/get[医]ID