From 8fe5fa56eeade4fc19c5401861c179c2fdfeaf3d Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 11 Sep 2011 12:35:41 -0400 Subject: [PATCH] fix serious bug in pthread_join on spurious wakeups/returns from __timedwait, pthread_join would "succeed" and unmap the thread's stack while it was still running. at best this would lead to SIGSEGV when the thread resumed execution, but in the worst case, the thread would later resume executing on top of another new thread's stack mapped at the same address. spent about 4 hours tracking this bug down, chasing rare difficult-to-reproduce stack corruption in a stress test program. still no idea *what* caused the spurious wakeups; i suspect it's a kernel bug. --- src/thread/pthread_join.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/thread/pthread_join.c b/src/thread/pthread_join.c index 1b0c4f35..86191f25 100644 --- a/src/thread/pthread_join.c +++ b/src/thread/pthread_join.c @@ -6,8 +6,8 @@ static void dummy(void *p) int pthread_join(pthread_t t, void **res) { - int tmp = t->tid; - if (tmp) __timedwait(&t->tid, tmp, 0, 0, dummy, 0, 0); + int tmp; + while ((tmp = t->tid)) __timedwait(&t->tid, tmp, 0, 0, dummy, 0, 0); if (res) *res = t->result; if (t->map_base) munmap(t->map_base, t->map_size); return 0; -- 2.25.1