在pthread_join()和了pthread_exit() [英] pthread_join() and pthread_exit()

查看:149
本文介绍了在pthread_join()和了pthread_exit()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于C并发编程的问题。

I have a question about C concurrency programming.

在pthread库,原型在pthread_join

In the pthread library, the prototype of pthread_join is

int pthread_join(pthread_t tid, void **ret);

了pthread_exit 的原型是:

void pthread_exit(void *ret);

所以我感到困惑的是,为什么在pthread_join 取过程的返回值作为一个指针到无效从收割线程指针,但了pthread_exit 只需无效从退出线程指针?我的意思是基本上他们是从一个线程,为什么在种类的不同所有的返回值?

So I am confused that, why pthread_join takes the return value of the process as a pointer to a void pointer from reaped thread, but pthread_exit only takes a void pointer from the exited thread? I mean basically they are all return values from a thread, why there is a difference in type?

推荐答案

了pthread_exit RET 是输入参数。你只是传递一个变量的地址的功能。

In pthread_exit, ret is an input parameter. You are simply passing the address of a variable to the function.

在pthread_join RET 是一个输出参数。你回来从函数的值。这样的值,例如,设置为 NULL

In pthread_join, ret is an output parameter. You get back a value from the function. Such value can, for example, be set to NULL.

龙解释:

在pthread_join ,你回来了成品线程传递给了pthread_exit 的地址。如果你通过只是一个普通的指针,它是按值传递的,所以你不能改变它指向。为了能够改变传递给在pthread_join指针的值时,它必须作为一个指针本身,也就是说,一指针的指针进行传递。

In pthread_join, you get back the address passed to pthread_exit by the finished thread. If you pass just a plain pointer, it is passed by value so you can't change where it is pointing to. To be able to change the value of the pointer passed to pthread_join, it must be passed as a pointer itself, that is, a pointer to a pointer.

这篇关于在pthread_join()和了pthread_exit()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆