This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Race and segmentation fault in pthread_kill() vs thread teardown
- From: Rich Felker <dalias at aerifal dot cx>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: Mathieu Desnoyers <mathieu dot desnoyers at efficios dot com>, David Miller <davem at davemloft dot net>, libc-alpha at sourceware dot org, "Paul E. McKenney" <paulmck at linux dot vnet dot ibm dot com>
- Date: Wed, 2 Oct 2013 17:10:36 -0400
- Subject: Re: Race and segmentation fault in pthread_kill() vs thread teardown
- Authentication-results: sourceware.org; auth=none
- References: <305581948 dot 26980 dot 1380684877897 dot JavaMail dot zimbra at efficios dot com> <675415986 dot 27031 dot 1380686764309 dot JavaMail dot zimbra at efficios dot com> <mvm8uyc2itw dot fsf at hawking dot suse dot de>
On Wed, Oct 02, 2013 at 10:11:23AM +0200, Andreas Schwab wrote:
> The POSIX spec is pretty clear:
>
> If an application attempts to use a thread ID whose lifetime has ended,
> the behavior is undefined.
>
> I'd suggest to file a bug report with the Austin group wrt to the
> wording in pthread_kill.
It's perfectly valid to use pthread_kill with a signal number of 0 to
determine whether the thread has exited, but only as long as the
thread ID is still valid. The only way it can still be valid is if the
thread was joinable and has not been joined. If a detached thread
exits or the thread is joined after exiting, the thread ID is invalid
and using it for any purpose invokes undefined behavior.
Rich