在pthread_join函数中使用指针指针

时间:2014-12-01 16:23:07

标签: c pthreads pthread-join

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

根据手册页pthread_join应该使用指向指针的指针作为参数来存储返回值。我无法理解为什么它的设计方式。在那里使用指针变量就足够了吗?

2 个答案:

答案 0 :(得分:2)

如果我清楚地理解了你的问题...... 你应该这样使用..

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

答案 1 :(得分:1)

传递给pthread_create的开始例程返回类型为Foobar的值。我不知道Foobar是什么,但如果您想在pthread_join中捕获该值,则必须传递Foobar*

现在,当我查看pthread_create文档时,我发现Foobar实际上是void*。因此pthread_join应接受void**