考虑下一段代码 -
pthread_t* threads;
void createWorkers(WorkerType type)
{
// Create mapper threads and their Container
for (int i = 0; i < poolSize; ++i)
{
// Add new Thread
ret = pthread_create(&threads[i], nullptr, function, nullptr);
// HERE THE MAIN THREAD PRINTS THE JUST CREATED THREAD ID (*)
}
}
int main()
{
createWorkers();
// JOINING THE THREADS
return 0;
}
父(主线程)有没有办法获得其子ID?例如,在行(*)?
中创建子项后答案 0 :(得分:1)
根据手册页,线程ID与pthread_t
返回的pthread_create
相同。所以你可以打印出来:
printf("%d", threads[i]);