From owner-freebsd-threads@FreeBSD.ORG Fri Dec 15 20:14:48 2006 Return-Path: X-Original-To: freebsd-threads@freebsd.org Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 83B6116A5C2 for ; Fri, 15 Dec 2006 20:14:48 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outE.internet-mail-service.net (outE.internet-mail-service.net [216.240.47.228]) by mx1.FreeBSD.org (Postfix) with ESMTP id 90E7D43CBA for ; Fri, 15 Dec 2006 20:12:48 +0000 (GMT) (envelope-from julian@elischer.org) Received: from shell.idiom.com (HELO idiom.com) (216.240.47.20) by out.internet-mail-service.net (qpsmtpd/0.32) with ESMTP; Fri, 15 Dec 2006 11:59:11 -0800 Received: from [10.251.18.229] (nat.ironport.com [63.251.108.100]) by idiom.com (8.12.11/8.12.11) with ESMTP id kBFKBhUL081251; Fri, 15 Dec 2006 12:11:44 -0800 (PST) (envelope-from julian@elischer.org) Message-ID: <45830177.304@elischer.org> Date: Fri, 15 Dec 2006 12:11:35 -0800 From: Julian Elischer User-Agent: Thunderbird 1.5.0.8 (Macintosh/20061025) MIME-Version: 1.0 To: Peter Edwards References: <34cb7c840612151000s4a3e1f2dvd71a60d66cf7c4be@mail.gmail.com> In-Reply-To: <34cb7c840612151000s4a3e1f2dvd71a60d66cf7c4be@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-threads@freebsd.org Subject: Re: libpthread problem + possible solution X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Dec 2006 20:14:48 -0000 Peter Edwards wrote: > Hi, > > I've a problem when a process uses: > libpthread > detached threads > mixed bound/unbound threads > suspended threads (a la pthread_resume_np()) > > whereby some newly created suspended threads don't get scheduled. > I think I've tracked it down, so if someone could review the > reasoning, I'd be grateful. > > Newly launched threads have a "struct pthread" that may be allocated > from a freelist of GCed threads. Apparently, when detached threads > enter the GCed list, they can still have the "active" flag set on > them. Later, this causes problems when this thread is recycled and > resumed, because _thr_setrunnable_unlocked() doesn't add it to a > run queue. > > thr_cleanup can be called either from the bound-threads scheduler, > or the unbound scheduler. One callsite clears "active", "needswitchout", > and "lock_switch" to zero before the call. The other callsite just > clears "check_pending". I think these flags are all either bound-thread > or unbound-thread specific, and that there was an unintended > assumption that the thread would remain with the same "boundedness" > after being recycled, which isn't neccessarily the case. (Or another > way - the idea was that there was no need to clear the "active" > flag on a bound thread, as its only used for unbound threads, but > a GCed bound thread might be recycled into an unbound thread) > > Given that, it seems correct to clean up the thread the same way > for both cases, and just move that code into thr_cleanup. So, does > the attached patch make sense? I can commit it if someone gives me > the nod. (It definitely fixes my specific problem with threads not > getting scheduled.) your logic sounds sound.. I'll wait for DAN to make a pronouncement however. > > > ------------------------------------------------------------------------ > > Index: lib/libpthread/thread/thr_kern.c > =================================================================== > RCS file: /net/dyson/export/home/petere/FreeBSD-CVS/src/lib/libpthread/thread/thr_kern.c,v > retrieving revision 1.116.2.1 > diff -u -r1.116.2.1 thr_kern.c > --- lib/libpthread/thread/thr_kern.c 16 Mar 2006 23:29:07 -0000 1.116.2.1 > +++ lib/libpthread/thread/thr_kern.c 15 Dec 2006 17:48:20 -0000 > @@ -764,7 +764,6 @@ > break; > > case PS_DEAD: > - curthread->check_pending = 0; > /* Unlock the scheduling queue and exit the KSE and thread. */ > thr_cleanup(curkse, curthread); > KSE_SCHED_UNLOCK(curkse, curkse->k_kseg); > @@ -1150,6 +1149,11 @@ > struct kse_mailbox *kmbx = NULL; > int sys_scope; > > + thread->active = 0; > + thread->need_switchout = 0; > + thread->lock_switch = 0; > + thread->check_pending = 0; > + > if ((joiner = thread->joiner) != NULL) { > /* Joinee scheduler lock held; joiner won't leave. */ > if (joiner->kseg == curkse->k_kseg) { > @@ -1717,9 +1721,6 @@ > * stack. It is safe to do garbage collecting > * here. > */ > - thread->active = 0; > - thread->need_switchout = 0; > - thread->lock_switch = 0; > thr_cleanup(kse, thread); > return; > break; > > > ------------------------------------------------------------------------ > > _______________________________________________ > freebsd-threads@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-threads > To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org"