我必须分离或加入pthread吗? [英] Must I detach or join a pthread?
问题描述
pthread_detach()
文件说明:
pthread_detach()
函数应该向执行
指示当线程
终止时线程线程的存储可以被回收。
The
pthread_detach()
function shall indicate to the implementation that storage for the thread thread can be reclaimed when that thread terminates.
如果我创建一个可加入线程,并且不分离或加入它,结果是什么?
What is the consequence if I create a joinable thread and do not detach or join it? The resources of that thread are not going to be reclaimed?
推荐答案
你回答了自己的问题吗?线程需要系统中的某些资源。这些将保持,直到螺纹被接合,或者其被分离并且其终止。 (直到你分离线程,系统必须假设你将在未来的某个时间加入它,并且不能释放资源。)
You answered your own question? A thread requires certain resources in the system. These will be kept until either the thread is joined, or it is detached and it terminates. (Until you detach the thread, the system must suppose that you will join it sometime in the future, and cannot free the resources.)
这篇关于我必须分离或加入pthread吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!