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。
该值独一地标识了一个线程。
Parameters
noneReturn 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
- C++11 this_thread::get_id(9)
- C++11 thread::get_id(3)
- C++11 this_thread::sleep_until(11)
- C++11 this_thread::sleep_for(10)
- C++11 this_thread::yeild(12)
- C++11 'yield' is not a member of 'std::this_thread'
- std :: this_thread
- C++11 error: ‘sleep_for’ is not a member of ‘std::this_thread’
- boost::this_thread::sleep_for()死锁
- std::this_thread::sleep_until
- std::this_thread::yield()使用理解
- 使用std::mutex(注意其中get_id()和sleep_for()
- Break the infinity thread loop using boost::this_thread::interruption_point()
- Boost编程之--慎用线程的this_thread::yield()方法
- 尽量不要在生产环境代码中使用boost::this_thread::sleep
- C(11)
- 11C
- Objective-c 第9-10-11章
- 读懂Spring核心系列3(自动装配属性)
- 数学建模高级方法(三):灰色关联分析,复相关系数
- poj 1679 The Unique MST
- yum 常用参数
- qt creator 在linux下不能调试的解决方案
- C++11 this_thread::get_id(9)
- poj 2656 Unhappy Jinjin
- elasticsearch-curator的安装
- QT Creator 快捷键
- 刚问过
- Subshell 执行
- QT QProcess::readAllStandardOutput()中文乱码解决方法
- linux参数太长续行,linux shell 参数换行(标准说法:续行)
- uva10026