#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一致。