Is it safe to call pthread_cancel() on terminated thread?

前端 未结 4 863
误落风尘
误落风尘 2021-02-08 00:45

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.

<
4条回答
  •  太阳男子
    2021-02-08 01:07

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

    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.

    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.

提交回复
热议问题