From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11775 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] thread: do not attempt to join detached threads in pthread_join() Date: Tue, 1 Aug 2017 18:56:02 -0400 Message-ID: <20170801225602.GE1627@brightrain.aerifal.cx> References: <20170801224613.9732-1-nenolod@dereferenced.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1501628176 16917 195.159.176.226 (1 Aug 2017 22:56:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 1 Aug 2017 22:56:16 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11788-gllmg-musl=m.gmane.org@lists.openwall.com Wed Aug 02 00:56:13 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dcg5C-000436-C8 for gllmg-musl@m.gmane.org; Wed, 02 Aug 2017 00:56:10 +0200 Original-Received: (qmail 14226 invoked by uid 550); 1 Aug 2017 22:56:14 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 14205 invoked from network); 1 Aug 2017 22:56:14 -0000 Content-Disposition: inline In-Reply-To: <20170801224613.9732-1-nenolod@dereferenced.org> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11775 Archived-At: On Tue, Aug 01, 2017 at 10:46:13PM +0000, William Pitcock wrote: > A thread which is detached releases it's resources and TCB upon thread termination. > Therefore a thread which is detached is not joinable as any underlying futex will not > be incremented, resulting in a deadlock. Accordingly, we return EINVAL instead of > attempting to wait on a detached thread. > > Other pthread implementations such as glibc NPTL and FreeBSD also reject attempts > to join detached threads with EINVAL. Since the behavior is undefined and *can't be defined* in the general case (where the detached thread may already have exited and its id may even have been reused for a new thread), if any change is to be made, the function should be made to crash in this case. Returning EINVAL hides the (serious) programming error. Rich