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.
Edit: 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.
I think it needs to be safe, or
pthread_cancelwould be problematic (next to unusable).Indeed, if it wouldn’t be safe, every call to
pthread_cancelwould 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_cancelmust be safe if the thread has terminated. Of course, this might not be the case for a terminated and joined thread.