在终止的线程上调用pthread_cancel()是否安全? [英] Is it safe to call pthread_cancel() on terminated thread?

查看:121
本文介绍了在终止的线程上调用pthread_cancel()是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在终止的线程上调用pthread_cancel()是否安全.我在手册页中找不到任何提示.预先感谢您的任何提示.

I'm wondering if it is safe to call pthread_cancel() on a terminated thread. I couldn't find any hints in the manual page. Thanks in advance for any hints.

也许我不够准确.我不是在不是谈论由较早的pthread_cancel()终止的线程,而是谈论只是从其线程函数返回的线程.

Maybe I wasn't accurate enough. I'm not talking about threads terminated by an earlier pthread_cancel() but about threads that simply returned from their thread function.

推荐答案

我认为需要是安全的,否则pthread_cancel会出现问题(几乎无法使用).

I think it needs to be safe, or pthread_cancel would be problematic (next to unusable).

的确,如果不安全,对pthread_cancel的每次调用都必须通过检查线程是否处于活动状态(并确保其保持活动状态直到您取消它)而变得非常复杂.一个简单的你还在那儿"是不会的.

Indeed, if it wouldn't be safe, every call to pthread_cancel would have to be enormously complicated by checking the thread is alive (and ensuring it stays alive until you get to cancel it). A simple "are you still there" wouldn't do.

最后,我认为如果线程终止,pthread_cancel 必须是安全的.当然,终止并加入线程可能不是这种情况.

In conclusion, I believe pthread_cancel must be safe if the thread has terminated. Of course, this might not be the case for a terminated and joined thread.

这篇关于在终止的线程上调用pthread_cancel()是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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