From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11777 Path: news.gmane.org!.POSTED!not-for-mail From: William Pitcock Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] thread: do not attempt to join detached threads in pthread_join() Date: Tue, 1 Aug 2017 23:12:03 +0000 Message-ID: <20170801231203.9829-1-nenolod@dereferenced.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1501629307 11397 195.159.176.226 (1 Aug 2017 23:15:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 1 Aug 2017 23:15:07 +0000 (UTC) Cc: William Pitcock To: musl@lists.openwall.com Original-X-From: musl-return-11790-gllmg-musl=m.gmane.org@lists.openwall.com Wed Aug 02 01:15:04 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 1dcgNR-0002bm-JC for gllmg-musl@m.gmane.org; Wed, 02 Aug 2017 01:15:01 +0200 Original-Received: (qmail 28230 invoked by uid 550); 1 Aug 2017 23:15:05 -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 28195 invoked from network); 1 Aug 2017 23:15:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dereferenced-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=DUflEMmgfUbfqM1NEtvaqqVZW6IXESPsFXCsrkN75hg=; b=L8Fm6FTdo3Hjfcjw3qLVv5cd7bSangczbDjDVhQKUHjiLwXCIq/aElp2YPz2tusJu3 u2WFhfdH3vNjAn01eHLyUGMIlwTibfD9X+8jgEwgZKP32GVjHLDQSxjDzsNWD7nBy7d5 xlICe5n/R97jbPD7v4CIYokGYHH6sLzvZjm1NHU8EKJ9I6xmkIHTtb1gAtAG1hMK6Bfb LYvWmiFXVod8BvQUvA4FSvcPCQlz0AyxSgtg5re+iFxrPQaC1kXxYUIskRwGcWAqZD+n V+IacA2oKM858T0yxUilhlT8D6LTfcGa7bbxm0Sv32uRUWo5yS5y4HuG1aTu8IpcD+ni L+VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DUflEMmgfUbfqM1NEtvaqqVZW6IXESPsFXCsrkN75hg=; b=cjdVFzhS2jQoMw82JXnwYUZqnNMyc3QHnhvqZM7NQVpcQ3uZza9sv9hRKmbaY5GeJb 9bXQ5oVSYWzh7JZOQdzUZpfr9GDdWvzhSzXZ24Ima2wxV4458+pEdesvtfDqAibHl8Jk eW7ZtZRQPsjc+DuY5Jzd6/nAla/GQMQIVckeUYvFUBjzNDi3T9YEE2yQ87zXahrAHKUi wan08KINWRGQ7qORIq/LOs+smYFWTAlG+ECvX9dTgm5FPU2+0YIEnV3iJ0lr/FPb6m7X JR7glV6HDUTT4CfILLWMK6xZNGaQQephXalfofGi5/79kwHdHet1FSi85XuDmhr97Z3H pwyA== X-Gm-Message-State: AIVw110Wnaidf53W73kIVsgPKt0Fs4z8cgzIOJdkbuRwkf+oYab62Tcg 0pPE3pnu88umN0a3UqU= X-Received: by 10.202.80.19 with SMTP id e19mr4022527oib.274.1501629292605; Tue, 01 Aug 2017 16:14:52 -0700 (PDT) X-Mailer: git-send-email 2.13.3 Xref: news.gmane.org gmane.linux.lib.musl.general:11777 Archived-At: 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, POSIX defines calling pthread_join() on a detached thread as undefined behaviour. We attempt, where possible, to detect attempts to join detached threads and crash instead, to bring the undefined behaviour to the programmer's attention. --- src/thread/pthread_join.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/thread/pthread_join.c b/src/thread/pthread_join.c index 52111489..b7175c09 100644 --- a/src/thread/pthread_join.c +++ b/src/thread/pthread_join.c @@ -11,6 +11,7 @@ int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at) __pthread_testcancel(); __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); if (cs == PTHREAD_CANCEL_ENABLE) __pthread_setcancelstate(cs, 0); + if (t->detached) a_crash(); while ((tmp = t->tid) && r != ETIMEDOUT && r != EINVAL) r = __timedwait_cp(&t->tid, tmp, CLOCK_REALTIME, at, 0); __pthread_setcancelstate(cs, 0); -- 2.13.3