鉴于以下情况:
pthread_t thread;
pthread_create(&thread, NULL, function, NULL);
到底是做什么的pthread_create
do to thread
?
会发生什么thread
在它加入主线程并终止之后?
-
如果之后会发生什么thread
已加入,您执行以下操作:
pthread_create(&thread, NULL, another_function, NULL);
pthread_create 对线程到底做了什么?
thread
是一个对象,它可以保存一个值来标识一个线程。如果pthread_create
成功后,它会填充一个标识新创建线程的值。如果失败,则值为thread
调用后未定义。 (参考:http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_create.html http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_create.html)
线程加入主线程并终止后会发生什么?
该对象没有发生任何事情,但它所持有的值不再引用任何线程(因此,例如,您不能再将它传递给采用pthread_t
,如果你不小心这样做了,那么你可能会得到ESRCH
错误返回)。
如果在线程加入后,您执行以下操作,会发生什么情况:
和以前一样:如果pthread_create
成功后,会分配一个值来标识新创建的线程。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)