내가 간단한 멀티 스레드 프로그램을 실행하려고하고 내가 GCC로부터는 pthread_create에서리턴 코드는 11
리턴 코드()입니다이 오류를 얻고 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 개의 스레드로 무엇을 하시겠습니까? 클러스터에 있습니까? – RedX
높은 스레드 수를 시작하려면 기본 스레드 스택 크기를 변경해야합니다. – osgx
osgx가 말한 바. 'pthread_attr_setstacksize'를보십시오. –