Date: Mon, 30 Aug 2004 15:06:08 -0400 From: John Baldwin <jhb@FreeBSD.org> To: freebsd-hackers@FreeBSD.org Cc: yangshazhou@hotmail.com Subject: Re: yield() in kernel CAN'T yield control for MOD_LOAD thread Message-ID: <200408301506.08829.jhb@FreeBSD.org> In-Reply-To: <BAY17-DAV17iKkZDDA300014158@hotmail.com> References: <BAY17-DAV17iKkZDDA300014158@hotmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <jhb@FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200408301506.08829.jhb>