|
Message-ID: <20150920183331.GN17773@brightrain.aerifal.cx> Date: Sun, 20 Sep 2015 14:33:31 -0400 From: Rich Felker <dalias@...c.org> To: musl@...ts.openwall.com Subject: Re: pthread_join stuck in infinite loop On Sun, Sep 20, 2015 at 08:07:28PM +0200, Julien Ramseier wrote: > Hello, > > pthread_join() never returns when calling it on a detached thread. > I would expect it to return EINVAL instead. Calling pthread_join on a detached thread or thread id which is no longer valid results in undefined behavior. You can't do it. See: http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html "The behavior is undefined if the value specified by the thread argument to pthread_join() does not refer to a joinable thread." and: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_02 "The lifetime of a thread ID ends after the thread terminates if it was created with the detachstate attribute set to PTHREAD_CREATE_DETACHED or if pthread_detach() or pthread_join() has been called for that thread. A conforming implementation is free to reuse a thread ID after its lifetime has ended. If an application attempts to use a thread ID whose lifetime has ended, the behavior is undefined. If a thread is detached, its thread ID is invalid for use as an argument in a call to pthread_detach() or pthread_join()." Note that it's fundamentally impossible for it to be well-defined for thread ids whose lifetimes have ended, and it wouldn't really make sense to have it be defined for still-live detached threads since, unless you perform additional synchronization to ensure this doesn't happen, it's possible that a detached thread's exit could race with your call to pthread_join and cause the id to become invalid. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.