From: William Pitcock <nenolod@dereferenced.org>
To: musl@lists.openwall.com
Cc: William Pitcock <nenolod@dereferenced.org>
Subject: [PATCH] thread: do not attempt to join detached threads in pthread_join()
Date: Tue, 1 Aug 2017 23:12:03 +0000 [thread overview]
Message-ID: <20170801231203.9829-1-nenolod@dereferenced.org> (raw)
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
next reply other threads:[~2017-08-01 23:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-01 23:12 William Pitcock [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-08-01 22:46 William Pitcock
2017-08-01 22:56 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170801231203.9829-1-nenolod@dereferenced.org \
--to=nenolod@dereferenced.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).