您的位置:首页 > 编程语言 > C语言/C++

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一致。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息