From owner-cvs-all@FreeBSD.ORG Mon Jul 23 19:20:34 2007 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 60C1816A41A for ; Mon, 23 Jul 2007 19:20:34 +0000 (UTC) (envelope-from nate@root.org) Received: from root.org (root.org [67.118.192.226]) by mx1.freebsd.org (Postfix) with ESMTP id F2F4713C491 for ; Mon, 23 Jul 2007 19:20:33 +0000 (UTC) (envelope-from nate@root.org) Received: (qmail 27473 invoked from network); 23 Jul 2007 19:20:34 -0000 Received: from ppp-71-139-42-13.dsl.snfc21.pacbell.net (HELO ?10.0.0.15?) (nate-mail@71.139.42.13) by root.org with ESMTPA; 23 Jul 2007 19:20:34 -0000 Message-ID: <46A4FF7B.5000501@root.org> Date: Mon, 23 Jul 2007 12:20:27 -0700 From: Nate Lawson User-Agent: Thunderbird 2.0.0.4 (X11/20070620) MIME-Version: 1.0 To: John Baldwin References: <200707222053.l6MKrS6v040649@repoman.freebsd.org> <200707231050.51004.jhb@freebsd.org> In-Reply-To: <200707231050.51004.jhb@freebsd.org> X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Cc: cvs-src@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org, Andrew Thompson Subject: Re: cvs commit: src/sys/compat/ndis subr_ntoskrnl.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jul 2007 19:20:34 -0000 John Baldwin wrote: > On Sunday 22 July 2007 04:53:28 pm Andrew Thompson wrote: >> thompsa 2007-07-22 20:53:28 UTC >> >> FreeBSD src repository >> >> Modified files: >> sys/compat/ndis subr_ntoskrnl.c >> Log: >> ndis will signal the kthread to exit and then sleep on the proc pointer to >> be woken up by kthread_exit. This is racey and in some cases the kthread > will >> exit before ndis gets around to sleep so it will be stuck indefinitely. > This >> change reuses the kq_exit variable to indicate that the thread has gone > and >> will loop on tsleep with a timeout waiting for it. If the kthread has > already >> exited then it will not sleep at all. > > As long as you use a lock you are ok. That is: > > foo_detach() > { > > mtx_lock(&lock); > please_die = 1; > msleep(&proc, &lock, ..., 0); > mtx_unlock(&lock); > } > > foo_main() > { > > mtx_lock(&lock); > while (!please_die) { > do_stuff(); > } > mtx_unlock(&lock); > kthread_exit(0); > } > > works fine. How can foo_detach() acquire the lock to set "please_die" if foo_main() always holds it? Are you assuming that "do_stuff()" drops the lock somewhere internally? -Nate