C++ 11 查看硬件线程个数等信息
2016-03-26 02:59
351 查看
#include <iostream> #include <thread> #include <pthread.h> #include <mutex> using namespace std; mutex mtx; void showinfo() { lock_guard<mutex> lk(mtx); cout<<"hardware thread is "<<thread::hardware_concurrency()<<endl; cout<<"thread id is "<<pthread_self()<<endl; cout<<"thread id is "<<this_thread::get_id()<<endl; } int main() { thread t1(showinfo); { lock_guard<mutex> lk(mtx); cout<<"thread native handle is "<<t1.native_handle()<<endl; } t1.join(); return 0; }
在linux下,线程原始句柄就是线程的ID。
在windows下(需将代码中与pthread相关的部分去掉),得到的线程ID和线程原始句柄不一样。
PS:在mingw下,信息与linux一致。
相关文章推荐
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 在 Qt4 中使用 C++11
- c++11新特性--decltype auto
- centos安装devtoolset-3支持gcc 4.9.2
- 使用eclipse编译含有C++11特性的代码
- 怎样在Linux环境编译支持C11
- eclipse支持c++11
- C++11可变参数函数与for循环
- vs2013 编译c++是发现惊天bug
- 简单性能测试函数模板
- 关于C++现状的一些思考
- 用C++11优化矩阵运算的空间和时间效率
- 浅析构造函数之默认构造函数
- c++中返回数组的函数
- C++函数重载的几个问题
- C++11 note-2 字符串 容器 迭代器
- C++11 现代C++风格的新元素
- c++11 lambda表达式浅谈
- C++11之“move”语意
- C++11之Lambda表达式