From owner-cvs-all@FreeBSD.ORG Mon Jul 23 19:55:37 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 9B89516A419; Mon, 23 Jul 2007 19:55:37 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from speedfactory.net (mail6.speedfactory.net [66.23.216.219]) by mx1.freebsd.org (Postfix) with ESMTP id 258BD13C468; Mon, 23 Jul 2007 19:55:36 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unverified [66.23.211.162]) by speedfactory.net (SurgeMail 3.7b8) with ESMTP id 198504747 for multiple; Mon, 23 Jul 2007 16:03:50 -0400 Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.13.8/8.13.8) with ESMTP id l6NJt2Dr002035; Mon, 23 Jul 2007 15:55:03 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: Nate Lawson Date: Mon, 23 Jul 2007 15:42:14 -0400 User-Agent: KMail/1.9.6 References: <200707222053.l6MKrS6v040649@repoman.freebsd.org> <200707231050.51004.jhb@freebsd.org> <46A4FF7B.5000501@root.org> In-Reply-To: <46A4FF7B.5000501@root.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200707231542.14803.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Mon, 23 Jul 2007 15:55:03 -0400 (EDT) X-Virus-Scanned: ClamAV 0.88.3/3743/Mon Jul 23 13:44:24 2007 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx X-Server: High Performance Mail Server - http://surgemail.com r=1653887525 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:55:37 -0000 On Monday 23 July 2007 03:20:27 pm Nate Lawson wrote: > 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? Yes, normally you do an msleep() to wait for work. -- John Baldwin