title: c++ pthread limit number of thread
body: <p>I tried to use pthread to do some task faster. I have thousands files (in args) to process and i want to create just a small number of thread many times.<br>
  Here's my code :</p>
  
  <pre><code>void callThread(){
      int nbt = 0;
      pthread_t *vp = (pthread_t*)malloc(sizeof(pthread_t)*NBTHREAD);
      for(int i=0;i&lt;args.size();i+=NBTHREAD){
          for(int j=0;j&lt;NBTHREAD;j++){
                if(i+j&lt;args.size()){
                     pthread_create(&amp;vp[j],NULL,calcul,&amp;args[i+j]);   
                     nbt++;
                }
          }
          for(int k=0;k&lt;nbt;k++){
                if(pthread_join(vp[k], NULL)){
                     cout&lt;&lt;"ERROR pthread_join()"&lt;&lt;endl;
                } 
          }
     }
  }
  </code></pre>
  
  <p>It returns error, i don't know if it's a good way to solve my problem. All the resources are in args (vector of struct) and are independants.<br>
  Thanks for help.</p>