我只是在玩弄线程来习惯它们,所以我想创建 20 个同时处于事件状态的线程,并编写了这个程序:
static void * threadFunc(void *str)
{
sleep(5);
}
int main (int argc, char * argv[])
{
pthread_t arr[20];
for(int i = 0; i < 20; i++)
{
pthread_create(&arr[i], NULL, threadFunc, (void*)NULL);
cout << "i=" << i << "\ntotal threads=" << pthread_is_threaded_np() << "\n";
}
}
但它一直说线程总数为 1。我在这里错过了什么?
最佳答案
你认为pthread_is_threaded_np()
会做什么?这里有一个提示:这不是您想要的。
关于c++ - 如何增加进程中运行的线程数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9370830/