I'm attempting to print a return value from pthread_join. I have the following code:
for(j = 0 ; j < i ; ++j){
pthread_join( tid[j], returnValue); /* BLOCK */
printf("%d\n", (int)&&returnValue);
}
All of the threads are stored in the tid array and are created and returned correctly. At the end of each thread function I have the following line:
pthread_exit((void *)buf.st_size);
I am attempting to return the size of some file I was reading. For some reason I cannot get it to print the correct value. It is more then likely the way I am attempting to dereference the void ** from the pthread_join function call, but I'm not too sure how to go about doing that. Thanks in advance for any help.
You need to pass the address of a void *
variable to pthread_join
-- it will get filled in with the exit value. That void *
then should be cast back to whatever type was originally stored into it by the pthread_exit
call:
for(j = 0 ; j < i ; ++j) {
void *returnValue;
pthread_join( tid[j], &returnValue); /* BLOCK */
printf("%zd\n", (size_t)(off_t)returnValue);
}