您需要加入已取消的主题吗? (pthreads) [英] Do you need to join a cancelled thread? (pthreads)

查看:135
本文介绍了您需要加入已取消的主题吗? (pthreads)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用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:


如果你需要知道线程何时实际终止,你必须
通过调用pthread_join取消它。

"If you need to know when the thread has actually terminated, you must join with it by calling pthread_join after cancelling it."

那么,我需要加入一个被取消的线程来释放它的资源 - 如果没有, / 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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