C++11 this_thread::get_id(9)

来源:互联网 发布:淘宝刷单权重 编辑:程序博客网 时间:2024/06/14 18:35
原文地址:http://www.cplusplus.com/reference/thread/this_thread/get_id/
function
<thread>

std::this_thread::get_id

thread::id get_id() noexcept;
Get thread id
Returns the thread id of the calling thread.

返回当前调用的线程ID。


This value uniquely identifies the thread.
该值独一地标识了一个线程。

Parameters

none

Return value

An object of member type thread::id that uniquely identifies the thread.
返回一个线程ID值独一地标识了一个线程。

Example

1234567891011121314151617181920
// thread::get_id / this_thread::get_id#include <iostream>       // std::cout#include <thread>         // std::thread, std::thread::id, std::this_thread::get_id#include <chrono>         // std::chrono::seconds std::thread::id main_thread_id = std::this_thread::get_id();//设置为全局所以该ID是主线程的IDvoid is_main_thread() {  if ( main_thread_id == std::this_thread::get_id() )    std::cout << "This is the main thread.\n";  else    std::cout << "This is not the main thread.\n";}int main() {  is_main_thread();  std::thread th (is_main_thread);  th.join();}
Edit & Run


Output:
This is the main thread.This is not the main thread.

Exception safety

No-throw guarantee: never throws exceptions.



—————————————————————————————————————————————————————————————————

//写的错误或者不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。

转载请注明出处:http://blog.csdn.net/qq844352155

author:天下无双

Email:coderguang@gmail.com

2014-9-4

于GDUT

——————————————————————————————————————————————————————————————————






0 0
原创粉丝点击