From owner-freebsd-threads@FreeBSD.ORG Fri Dec 15 18:00:06 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 C8F7716A416 for ; Fri, 15 Dec 2006 18:00:06 +0000 (UTC) (envelope-from peadar.edwards@gmail.com) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.234]) by mx1.FreeBSD.org (Postfix) with ESMTP id CB79243CC1 for ; Fri, 15 Dec 2006 17:58:22 +0000 (GMT) (envelope-from peadar.edwards@gmail.com) Received: by wr-out-0506.google.com with SMTP id i28so454270wra for ; Fri, 15 Dec 2006 10:00:04 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:mime-version:content-type:x-google-sender-auth; b=Z+M3OP8hX3iB1Hw0PzzIdUdeErnTCLntlnzIsB33LlIdZ1So45a/VULU92JrGul0hSm6Kc036/O48o6kqqqNdeOq5mvDmdZN583Pp6a0fP3rrUP+LoZG4uZwHwaUnEwDwB2fwwI2fAByxS3nmg8jA2PW4Jmo4GrwxVxwrPST464= Received: by 10.90.105.20 with SMTP id d20mr1088236agc.1166205604817; Fri, 15 Dec 2006 10:00:04 -0800 (PST) Received: by 10.90.89.13 with HTTP; Fri, 15 Dec 2006 10:00:04 -0800 (PST) Message-ID: <34cb7c840612151000s4a3e1f2dvd71a60d66cf7c4be@mail.gmail.com> Date: Fri, 15 Dec 2006 18:00:04 +0000 From: "Peter Edwards" Sender: peadar.edwards@gmail.com To: freebsd-threads@freebsd.org MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_115896_14548060.1166205604757" X-Google-Sender-Auth: cc95d030bb96a45a Subject: 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 18:00:07 -0000 ------=_Part_115896_14548060.1166205604757 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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.) ------=_Part_115896_14548060.1166205604757 Content-Type: text/plain; name=pthread.txt; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: base64 X-Attachment-Id: f_evqwn9nn Content-Disposition: attachment; filename="pthread.txt" SW5kZXg6IGxpYi9saWJwdGhyZWFkL3RocmVhZC90aHJfa2Vybi5jCj09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KUkNTIGZp bGU6IC9uZXQvZHlzb24vZXhwb3J0L2hvbWUvcGV0ZXJlL0ZyZWVCU0QtQ1ZTL3NyYy9saWIvbGli cHRocmVhZC90aHJlYWQvdGhyX2tlcm4uYyx2CnJldHJpZXZpbmcgcmV2aX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