这是因为每一次
void pthread_exit(void *ret);
将从所以它永远要简单地返回其指针传递用了pthread_exit()线程函数被调用。
现在在
int pthread_join(pthread_t tid, void **ret);
将从创建线程地方所以在这里接受返回的指针总是叫你需要双指针 ..
我认为这个代码将帮助你了解这个
#include<stdio.h>
#include<pthread.h>
#include<stdlib.h>
void* thread_function(void)
{
char *a = malloc(10);
strcpy(a,"hello world");
pthread_exit((void*)a);
}
int main()
{
pthread_t thread_id;
char *b;
pthread_create (&thread_id, NULL,&thread_function, NULL);
pthread_join(thread_id,(void**)&b); //here we are reciving one pointer
value so to use that we need double pointer
printf("b is %s",b);
free(b); // lets free the memory
}
但是为什么在`pthread_exit`中定义一个`void *`类型,它总是`NULL`或者其他一些常量值 – stonestrong 2014-02-13 08:22:37