diff options
| author | christos <christos@NetBSD.org> | 2009-10-03 23:49:50 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2009-10-03 23:49:50 +0000 |
| commit | 85ddadbfdc69ce282e56b47db2a644b6df2f739f (patch) | |
| tree | 72b4f0fc7138cc6b8278dda80aaf67dcf462903f /lib/libpthread | |
| parent | c9bb67bb7babe742b8a1be5ac5b6f04b89f76ada (diff) | |
Don't just look only at the first element in the deadqueue to find lwp's
to reuse, because if we lose the race with the kernel we are never going
to reuse any elements. Look in the whole list instead.
XXX: should be pulled up to 5.x
Diffstat (limited to 'lib/libpthread')
| -rw-r--r-- | lib/libpthread/pthread.c | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/lib/libpthread/pthread.c b/lib/libpthread/pthread.c index 74c9ef8c729..433573ccfbc 100644 --- a/lib/libpthread/pthread.c +++ b/lib/libpthread/pthread.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread.c,v 1.112 2009/07/02 09:59:00 joerg Exp $ */ +/* $NetBSD: pthread.c,v 1.113 2009/10/03 23:49:50 christos Exp $ */ /*- * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread.c,v 1.112 2009/07/02 09:59:00 joerg Exp $"); +__RCSID("$NetBSD: pthread.c,v 1.113 2009/10/03 23:49:50 christos Exp $"); #define __EXPOSE_STACK 1 @@ -353,23 +353,17 @@ pthread_create(pthread_t *thread, const pthread_attr_t *attr, */ if (!PTQ_EMPTY(&pthread__deadqueue)) { pthread_mutex_lock(&pthread__deadqueue_lock); - newthread = PTQ_FIRST(&pthread__deadqueue); - if (newthread != NULL) { - PTQ_REMOVE(&pthread__deadqueue, newthread, pt_deadq); - pthread_mutex_unlock(&pthread__deadqueue_lock); + PTQ_FOREACH(newthread, &pthread__deadqueue, pt_deadq) { /* Still running? */ - if (newthread->pt_lwpctl->lc_curcpu != - LWPCTL_CPU_EXITED && - (_lwp_kill(newthread->pt_lid, 0) == 0 || - errno != ESRCH)) { - pthread_mutex_lock(&pthread__deadqueue_lock); - PTQ_INSERT_TAIL(&pthread__deadqueue, - newthread, pt_deadq); - pthread_mutex_unlock(&pthread__deadqueue_lock); - newthread = NULL; - } - } else - pthread_mutex_unlock(&pthread__deadqueue_lock); + if (newthread->pt_lwpctl->lc_curcpu == + LWPCTL_CPU_EXITED || + (_lwp_kill(newthread->pt_lid, 0) == -1 && + errno == ESRCH)) + break; + } + if (newthread) + PTQ_REMOVE(&pthread__deadqueue, newthread, pt_deadq); + pthread_mutex_unlock(&pthread__deadqueue_lock); } /* |
