我想知道 pthread_join 中的“status”参数到底是用来做什么的
int pthread_join(pthread_t thread, void **status);
我正在尝试利用它,但我无法理解它到底代表什么。
根据文档
status
Is the location where the exit status of the joined thread is stored.
如果退出,则可以将其设置为 NULL
状态不是必需的。
好的。听起来不错。我该如何使用它?我看过一些例子,但我不能
掌握它的窍门(有些例子在使用它时是完全错误的)。所以我去了
来源。在 glibc 实现中,我发现了以下 pthread_join 测试:
...
pthread_t mh = (pthread_t) arg;
void *result;
...
if (pthread_join (mh, &result) != 0)
{
puts ("join failed");
exit (1);
}
here follows the WTF moment ...
if (result != (void *) 42l)
{
printf ("result wrong: expected %p, got %p\n", (void *) 42, result);
exit (1);
}
所以结果(这是一个地址)的值应该是42?这是全球性的吗
在图书馆级别,因为我找不到任何具体内容test http://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/tst-join1.c;h=95a78ba0b546303801591021923a7f77656a2909;hb=master?
编辑:看来这个问题 https://stackoverflow.com/questions/3692591/return-versus-pthread-exit-in-pthread-start-functions提供与我询问的内容相关的信息