c++ - 如何增加进程中运行的线程数?

标签 c++ multithreading pthreads parallel-processing

我只是在玩弄线程来习惯它们,所以我想创建 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/

相关文章:

c++ - 如何使用 cin 实现单行整数类型命令行输入验证?

python - 如何在不锁定的情况下在python中的多个进程之间共享字典

linux - 我如何决定调用 pthread_attr_setstacksize 后可以使用多少堆栈?

java - 在现有的 Swing 项目中使用 JavaFX 的 MediaPlayer

c - 如何与Linux中的线程共享主程序的内存

c++ - 检查当前线程是否为主线程

c++ - 转换函数/运算符,静态解析函数还是转换构造函数?

c++ - 错误 : call to implicitly-deleted copy constructor of 'std::__1::unique_ptr<A, std::__1::default_delete<A>>'

c++ - delete[] "know"操作数数组的大小如何?

multithreading - 如何在 Node.js 应用程序中使用 Apache OpenNLP