From: http://linux.die.net/man/3/pthread_join
If the thread calling pthread_join() is canceled, then the target thread will remain joinable (i.e., it will not be detached).
Does this mean that the target threads will not get aborted if we cancel the main thread calling pthread_join?
pthread_join()doesn’t ‘abort’ a target thread in the first place, so I’m not sure if I fully understand the question.Basically, if a thread (the main thread or otherwise) calls
pthread_join()it is asking to block until the target thread has exited. In the normal case, once the target thread has exited,the thread that calledpthread_join()will unblock and any resources that were associated witht he target thread can be freed by the system.However, if a thread has called
pthread_join()(and is blocked waiting for the target thread to exit) and the blocked thread gets cancelled, then essentially nothing happens to the target of thepthread_join()call (it continues on). What the docs are clarifying is that that thread remains ‘joinable’ – which means:pthread_join()to wait for it to finishpthread_detach()is called for the target thread. callingpthread_detach()for a thread makes it ‘unjoinable’ – it continues running and it’s resources will get freed when it exits (the detach call indicates to the system that nothing will use those resources after the thread exits), but no thread can join it anymore.