aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/2001-thread-do-not-attempt-to-join-detached-threads-in-pt.patch
diff options
context:
space:
mode:
Diffstat (limited to 'main/musl/2001-thread-do-not-attempt-to-join-detached-threads-in-pt.patch')
-rw-r--r--main/musl/2001-thread-do-not-attempt-to-join-detached-threads-in-pt.patch32
1 files changed, 32 insertions, 0 deletions
diff --git a/main/musl/2001-thread-do-not-attempt-to-join-detached-threads-in-pt.patch b/main/musl/2001-thread-do-not-attempt-to-join-detached-threads-in-pt.patch
new file mode 100644
index 0000000000..4fc5c05095
--- /dev/null
+++ b/main/musl/2001-thread-do-not-attempt-to-join-detached-threads-in-pt.patch
@@ -0,0 +1,32 @@
+From 602a22f1b626f84e9f7117940c06f4890c584d2a Mon Sep 17 00:00:00 2001
+From: William Pitcock <nenolod@dereferenced.org>
+Date: Tue, 1 Aug 2017 22:23:25 +0000
+Subject: [PATCH] thread: do not attempt to join detached threads in
+ pthread_join()
+
+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.
+---
+ 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..7c4bde23 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) r = EINVAL;
+ while ((tmp = t->tid) && r != ETIMEDOUT && r != EINVAL)
+ r = __timedwait_cp(&t->tid, tmp, CLOCK_REALTIME, at, 0);
+ __pthread_setcancelstate(cs, 0);
+--
+2.13.2
+