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:
threads = malloc(number_of_threads * sizeof(pthread_t));
Then I create each thread in a for-loop:
pthread_create(&(threads[i]), NULL, client_pipe_run, (void *) ¶m[i]);
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:
int *return_vals = malloc(sizeof(int) * number_of_threads);
for(i = 0; i< number_of_threads; i++)
{
pthread_join(&(threads[i]),(void *) &(return_vals[i]));
}
Then to get the return value I would do something similar to:
int val = *(return_val[0]);
Any help on the this would be greatly appreciated!