问题描述
我对使用PThreads取消订单时的清理顺序有点困惑。通常,如果你的线程是分离的,它会自动清除,当它终止。如果它不是分离的,你需要加入它来回收系统资源。
I'm a little confused about clean-up order when you're using PThreads with regard to cancellation. Normally, if your thread is detached, it automatically cleans up when it terminates. If it's not detached, you need to join it to reclaim the system resources.
我正在阅读的教科书说明下面这些奇怪听起来像加入是可选的取消:
The textbook I'm reading states the following which strangely sounds like joining is optional with regard to cancellation:
那么,我需要加入一个被取消的线程来释放它的资源 - 如果没有, / p>
So, do I need to join a cancelled thread to free its resources - and if not, then why?
推荐答案
TLPI说:
此外,由于取消一个线程通常不会立即完成(阅读更多关于取消点),而不加入你不能肯定线程实际上已取消。
Also, since canceling a thread isn't usually done immediately (read more about "cancellation points") without joining you can't be sure the thread was actually canceled.
这篇关于您需要加入已取消的主题吗? (pthreads)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!