1
votes
int pthread_join(pthread_t thread, void **retval);

According to the man page pthread_join should use a pointer to a pointer as argument to store the return value.I cant understand why its designed that way.Is it sufficient to use a pointer variable in that ?

2
Just because you don't understand it doesn't mean it will work if you don't follow the function's spec. - Scott Hunter
It receives the pointer you returned from your thread proc (which has a void* result). That value has to be stored somewhere. The pthread_join result would be a candidate, but it is used to convey the function success/failure result. Thus, an out-param is born. As an out-param in C, it provides the target as an address, thus the pointer-to-pointer. - WhozCraig
It's designed that way so that the thread can store a void* somewhere that is not going to go away when the thread does. - Martin James

2 Answers

2
votes

If I have understood your query clearly.. you should use like this..

pthread_t a_thread;
void *thread_result;
pthread_join(a_thread, &thread_result);
1
votes

The start routine you pass to pthread_create returns a value of type Foobar. I don't know what Foobar is, but if you want to capture that value in pthread_join, you have to pass a Foobar* in.

Now when I look at pthread_create documentation, I see that Foobar is actually void*. Hence pthread_join should accept void**.