Cancelling detached threads (posix threads)?
Jason Nye wrote: > I’m trying to find out whether the posix specification allows the > cancellation of detached threads. I have a copy of Butenhof’s book and in > the posix mini-reference at the end of the book, he says that pthread_cancel > should fail if the target thread is detached. This makes sense to me, but is > this the correct behaviour? For example LinuxThreads does allow cancellation > of a detached thread — who is correct? This is actually an ambiguity in the standard. An implementation that allows cancellation of a detached thread doesn’t violate the standard. HOWEVER, other provisions of the standard make such an allowance of questionable value, at best. For example, when a detached thread terminates the state of that thread is immediately invalidated, and may be reused immediately for a new thread. At that point (which you cannot determine) you would be cancelling some new thread that you probably didn’t create, with possibly disastrous consequences to your application.