Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Date: Tue,  1 Aug 2017 23:12:03 +0000
From: William Pitcock <>
Cc: William Pitcock <>
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, 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_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);

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.