I am following this tutorial on pthreads:
https://computing.llnl.gov/tutorials/pthreads/#Abstract
and there is this example of passing in multiple arguments via a struct:
struct thread_data{
int thread_id;
int sum;
char *message;
};
struct thread_data thread_data_array[NUM_THREADS];
int main (int argc, char *argv[])
{
...
thread_data_array[t].thread_id = t;
thread_data_array[t].sum = sum;
thread_data_array[t].message = messages[t];
rc = pthread_create(&threads[t], NULL, PrintHello, (void *) &thread_data_array[t]);
...
}
and this example showing how NOT to pass a single argument:
int rc;
long t;
for(t=0; t<NUM_THREADS; t++)
{
printf("Creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *) &t);
...
}
I don't understand why the last scenario is wrong, because it passes the address of t. However doesn't the first scenario pass the address of the thread_data struct?