* Re: Race and segmentation fault in pthread_kill() vs thread teardown [not found] ` <mvm8uyc2itw.fsf@hawking.suse.de> @ 2013-10-02 12:04 ` Mathieu Desnoyers 2013-10-02 18:05 ` Roland McGrath 2013-12-28 13:11 ` Michael Kerrisk (man-pages) 0 siblings, 2 replies; 3+ messages in thread From: Mathieu Desnoyers @ 2013-10-02 12:04 UTC (permalink / raw) To: Andreas Schwab, Michael Kerrisk Cc: David Miller, libc-alpha, Paul E. McKenney, linux-man ----- Original Message ----- > From: "Andreas Schwab" <schwab@suse.de> > To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com> > Cc: "David Miller" <davem@davemloft.net>, libc-alpha@sourceware.org, "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> > Sent: Wednesday, October 2, 2013 4:11:23 AM > Subject: Re: Race and segmentation fault in pthread_kill() vs thread teardown > > 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. CCing man pages maintainers, Interestingly enough, the specification has been updated: http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_kill.html to remove the ESRCH return value in Issue 7 Austin Group Interpretation 1003.1-2001 #142 is applied, removing the [ESRCH] error condition. It looks like a discrepancy between the spec and the man page that causes this confusion. We might want to update pthread_kill(3), keeping ESRCH documented, but clearly marked as deprecated, and clarify that calling pthread_kill() on a non-existing thread is undefined. We should probably remove this part entirely: " but error checking is still per‐ formed; this can be used to check for the existence of a thread ID." Thoughts ? Thanks, Mathieu > > Andreas. > > -- > Andreas Schwab, SUSE Labs, schwab@suse.de > GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 > "And now for something completely different." > -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Race and segmentation fault in pthread_kill() vs thread teardown 2013-10-02 12:04 ` Race and segmentation fault in pthread_kill() vs thread teardown Mathieu Desnoyers @ 2013-10-02 18:05 ` Roland McGrath 2013-12-28 13:11 ` Michael Kerrisk (man-pages) 1 sibling, 0 replies; 3+ messages in thread From: Roland McGrath @ 2013-10-02 18:05 UTC (permalink / raw) To: Mathieu Desnoyers Cc: Andreas Schwab, Michael Kerrisk, David Miller, libc-alpha, Paul E. McKenney, linux-man Yes, the man page is wrong. It was an error in the earlier version of the spec that it indicated it's ever possible to do any operation with a pthread_t that is not known to be an unjoined or live (if detached) thread. It's never been possible to use a possibly-stale pthread_t for anything in NPTL. There is no way to interrogate the system for whether a pthread_t value is valid--just like a pointer (which, in fact pthread_t is in our implementation), either it's valid or using it is undefined behavior. ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Race and segmentation fault in pthread_kill() vs thread teardown 2013-10-02 12:04 ` Race and segmentation fault in pthread_kill() vs thread teardown Mathieu Desnoyers 2013-10-02 18:05 ` Roland McGrath @ 2013-12-28 13:11 ` Michael Kerrisk (man-pages) 1 sibling, 0 replies; 3+ messages in thread From: Michael Kerrisk (man-pages) @ 2013-12-28 13:11 UTC (permalink / raw) To: Mathieu Desnoyers, Andreas Schwab Cc: mtk.manpages, David Miller, libc-alpha, Paul E. McKenney, linux-man, Roland McGrath On 10/03/13 01:04, Mathieu Desnoyers wrote: > ----- Original Message ----- >> From: "Andreas Schwab" <schwab@suse.de> >> To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com> >> Cc: "David Miller" <davem@davemloft.net>, libc-alpha@sourceware.org, "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> >> Sent: Wednesday, October 2, 2013 4:11:23 AM >> Subject: Re: Race and segmentation fault in pthread_kill() vs thread teardown >> >> 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. > > CCing man pages maintainers, > > Interestingly enough, the specification has been updated: > > http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_kill.html > > to remove the ESRCH return value in > > Issue 7 > Austin Group Interpretation 1003.1-2001 #142 is applied, removing the [ESRCH] error condition. > > It looks like a discrepancy between the spec and the man page that causes this confusion. We might want to update pthread_kill(3), keeping ESRCH documented, but clearly marked as deprecated, and clarify that calling pthread_kill() on a non-existing thread is undefined. > > We should probably remove this part entirely: > > " but error checking is still per‐ > formed; this can be used to check for the existence of a thread ID." > > Thoughts ? Mathieu, et al. I applied the patch below. Look okay to you? Cheers, Michael diff --git a/man3/pthread_kill.3 b/man3/pthread_kill.3 index 674168f..bbf5573 100644 --- a/man3/pthread_kill.3 +++ b/man3/pthread_kill.3 @@ -47,8 +47,7 @@ The signal is asynchronously directed to If .I sig -is 0, then no signal is sent, but error checking is still performed; -this can be used to check for the existence of a thread ID. +is 0, then no signal is sent, but error checking is still performed. .SH RETURN VALUE On success, .BR pthread_kill () @@ -58,13 +57,8 @@ on error, it returns an error number, and no signal is sent. .TP .B EINVAL An invalid signal was specified. -.TP -.B ESRCH -No thread with the ID -.I thread -could be found. .SH CONFORMING TO -POSIX.1-2001. +POSIX.1-2008. .SH NOTES Signal dispositions are process-wide: if a signal handler is installed, @@ -72,6 +66,19 @@ the handler will be invoked in the thread .IR thread , but if the disposition of the signal is "stop", "continue", or "terminate", this action will affect the whole process. + +POSIX.1-2008 recommends that if an implementation detects the use +of a thread ID after the end of its lifetime, +.BR pthread_kill () +should return the error +.BR ESRCH . +The glibc implementation returns this error in the cases where +an invalid thread ID can be detected. +But note also that POSIX says that an attempt to use a thread ID whose +lifetime has ended produces undefined behavior, +and an attempt to use an invalid thread ID in a call to +.BR pthread_kill () +can, for example, cause a segmentation fault. .SH SEE ALSO .BR kill (2), .BR sigaction (2), ^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-12-28 13:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <305581948.26980.1380684877897.JavaMail.zimbra@efficios.com>
[not found] ` <675415986.27031.1380686764309.JavaMail.zimbra@efficios.com>
[not found] ` <mvm8uyc2itw.fsf@hawking.suse.de>
2013-10-02 12:04 ` Race and segmentation fault in pthread_kill() vs thread teardown Mathieu Desnoyers
2013-10-02 18:05 ` Roland McGrath
2013-12-28 13:11 ` Michael Kerrisk (man-pages)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).