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

前端 未结 4 877
误落风尘
误落风尘 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 00:57

    No, it isn't safe to call pthread_cancel() on a thread that has been terminated.

    The reason is that the implementation may reuse the thread ID of the terminated thread for another thread and calling "pthread_cancel()" on that TID may trigger the termination on threads that shouldn't be terminated or undefined behaviour.

提交回复
热议问题