c++ - pthread_exit(NULL); not working -


this code creating threads. want create 500 threads in same time, not more. easy, code failed after 32xxx threads created.

then don't understand why error code 11 after 32751 threads, because, each thread ended.

i can understand, if threads don't exit, 32751 threads on same computer ... here, each thread exited.

here code :

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h>  void *test_tcp(void *);  int main ()     {     pthread_t threads[500];     int pointeur_thread;     unsigned long compteur_de_thread=0;     long ttt=0;     int i;      for(int i=0;i<=1000000;i++)         {         ttt++;         pointeur_thread=pthread_create(&threads[compteur_de_thread],null,test_tcp,null);         if (pointeur_thread!=0)             {             printf("error : %d\n",pointeur_thread);             exit(0);             }         printf("pointeur_thread : %d - thread : %ld - compteur_de_thread : %ld\n",pointeur_thread,compteur_de_thread,ttt);          compteur_de_thread++;         if (compteur_de_thread>=500)             compteur_de_thread=0;         }     printf("the end\n");     }  void *test_tcp(void *thread_arg_void)     {     pthread_exit(null);     } 

you're getting error value corresponds eagain, means: insufficient resources create thread.

the problem you're not joining threads after exit. done in if statement check if ids have been used: if (compteur_de_thread>=500).
loop on array , call pthread_join on elements of said array.


Comments