From owner-freebsd-hackers@FreeBSD.ORG Mon Aug 30 20:58:27 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C94B616A691 for ; Mon, 30 Aug 2004 20:58:26 +0000 (GMT) Received: from mail6.speakeasy.net (mail6.speakeasy.net [216.254.0.206]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5DEC343D69 for ; Mon, 30 Aug 2004 20:58:25 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: (qmail 20682 invoked from network); 30 Aug 2004 20:58:25 -0000 Received: from dsl027-160-063.atl1.dsl.speakeasy.net (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) encrypted SMTP for ; 30 Aug 2004 20:58:24 -0000 Received: from [10.50.41.228] (gw1.twc.weather.com [216.133.140.1]) (authenticated bits=0) by server.baldwin.cx (8.12.11/8.12.11) with ESMTP id i7UKvvMp045297; Mon, 30 Aug 2004 16:58:21 -0400 (EDT) (envelope-from jhb@FreeBSD.org) From: John Baldwin To: freebsd-hackers@FreeBSD.org Date: Mon, 30 Aug 2004 15:06:08 -0400 User-Agent: KMail/1.6.2 References: In-Reply-To: MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 7bit Message-Id: <200408301506.08829.jhb@FreeBSD.org> X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on server.baldwin.cx cc: yangshazhou@hotmail.com Subject: Re: yield() in kernel CAN'T yield control for MOD_LOAD thread X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Aug 2004 20:58:27 -0000 On Thursday 26 August 2004 02:36 am, yangshazhou@hotmail.com wrote: > Now "tsleep(&ident,PRIBIO,NULL,1)" solved the problem. Maybe yield() can't > do the job in kernel. And mi_switch() is not enough to.Thank you.On yield() can just switch back to you immediately since you (the current thread) are still runnable. Use a sleep, either via sleep/wakeup, or doing a tsleep with a timeout forces the current thread to not be runnable for a while giving the other thread time to run. Note that your tsleep(..., 1) is still racey, you really need to use sleep/wakeup to truly close the race. > Wednesday 25 August 2004 03:06 am, yangshazhou at hotmail.com wrote: > > Hi all, > > This problem delay me for quite a long time. > > I've built two klds, I'd like to see the result one's running to the > > other's. In one kld's MOD_LOAD subroutine, I make a long 'for' loop, in > > which it DELAY(1000) and then call yield(curthread,NULL). When the module > > was loaded by kldload, the system failed to response until the loop quit. > > The loop seems like that: > > for(i=0;i<8000;i++){ > > ...... > > DELAY(1000); > > yield(curthread,NULL); > > } > > > > My system is 5.2.1-release. Thanks. > > You could try having the first one wait on a condition variable that the > second module's MOD_LOAD does a wakeup on. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org