linux 开多(N)线程 获得线程ID

#include <pthread.h>

 vector<uint> m_vectSelectDataHander;

typedef map<int, int> templatemap;

templatemap MapPthreadID;

void *thread1(void*)
{

int nPthread = MapPthreadID[pthread_self()];

}

 for(int i=0;i<n;i++)
  m_vectSelectDataHander.push_back(0);

for(uint i = 0; i < m_vectSelectDataHander.size(); i++)
 {
  pthread_create((pthread_t*) & m_vectSelectDataHander[i], NULL, &thread1, NULL);
  int nPthreadID = m_vectSelectDataHander[i];
  MapPthreadID[nPthreadID]=i;
 }

 for(uint i = 0; i < m_vectSelectDataHander.size(); i++)
 pthread_join(m_vectSelectDataHander[i],NULL);

原文地址:https://www.cnblogs.com/byfei/p/3112275.html