- 论坛徽章:
- 0
|
原帖由 jiufei19 于 2009-10-20 17:32 发表
根据aupe,pthread_exit((void *)2); 于是通过pthread_join所得到的返回值就是2,所以我还是不明白呢?能否再阐述下,谢谢!
(void *)2 本质上是一个内存地址(虽然地址也是整数或长整数)。个人认为这种用法算是一种使用技巧(或者说是一种剑走偏锋的用法)。
我觉得这样
struct x {
int a;
int b;
char *str;
};
struct x *value = malloc(sizeof(struct x));
memset(value, 0, sizeof(struct x));
x->a = 10;
x->b = 20;
x->str = strdup("This is result from thread.");
pthread_exit(x);
----------------------
在发起调用的线程处
通过
struct x *ret;
pthread_join(tid, &ret);
printf("%d, %d, %s\n", ret->a, ret->b, ret->str);
才是pthread_exit()/pthread_join()的主要用法(虽然实际应用中我们通常只回传一个整数)
[ 本帖最后由 weichongli 于 2009-10-20 17:55 编辑 ] |
|