title: pthread Return Values to an Array
body: <p>I am currently working on a project that uses pthreads. The project so far starts a user specified number of threads and does some work on each thread then closes. Each thread is stored in a dynamically allocated array of memory. I do this using:</p>
  
  <p><code>threads = malloc(number_of_threads * sizeof(pthread_t));</code></p>
  
  <p>Then I create each thread in a for-loop: </p>
  
  <pre><code>pthread_create(&amp;(threads[i]), NULL, client_pipe_run, (void *) &amp;param[i]);
  </code></pre>
  
  <p>What I need to do next is store the return values of these threads. My understanding is that I need to pass pthread_join the address of a pointer I want to have the return value stored in. This is where I get a little confused. I'm fine with pointers up to this point then my brain kind of has a melt down haha. This is my idea on how to acheive this but I'm not confident that this is correct:</p>
  
  <pre><code>int *return_vals = malloc(sizeof(int) * number_of_threads);
  for(i = 0; i&lt; number_of_threads; i++)
  {
  pthread_join(&amp;(threads[i]),(void *) &amp;(return_vals[i]));
  }
  </code></pre>
  
  <p>Then to get the return value I would do something similar to:</p>
  
  <pre><code>int val = *(return_val[0]);
  </code></pre>
  
  <p>Any help on the this would be greatly appreciated!</p>