【发布时间】:2011-08-12 10:06:41
【问题描述】:
我正在尝试运行一个简单的多线程编程,但我从 gcc 收到此错误
pthread_create() 的返回码是 11
我该如何解决这个问题?
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS 20000
void *PrintHello(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
}
int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0; t<NUM_THREADS; t++){
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
/* Last thing that main() should do */
pthread_exit(NULL);
}
【问题讨论】:
-
20000个线程要做什么?你在集群上吗?
-
您应该更改默认线程堆栈大小以启动大量线程。
-
osgx 说了什么。见
pthread_attr_setstacksize。 -
@RedX 测试,我正在学习多线程编程,并试图弄清楚整个系统的速度。
标签: c multithreading gcc