Date: Tue, 23 Feb 2010 11:13:11 -0800 From: Julian Elischer <julian@elischer.org> To: Shrivatsan <shrivatsan_v@yahoo.com> Cc: freebsd-hackers@FreeBSD.org, shrivatsan@gmail.com Subject: Re: sched_lock mutex and sleepq_wait Message-ID: <4B8428C7.8010705@elischer.org> In-Reply-To: <986041.3700.qm@web112005.mail.gq1.yahoo.com> References: <986041.3700.qm@web112005.mail.gq1.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Shrivatsan wrote: > Hi, > > I am trying to understand how msleep() routine suspends the currently > executing thread. I see that msleep() calls sleepq_wait(). > > What I don't understand here is the way in which sched_lock mutex is > handled. > > I took the following snippet from FreeBSD 6: > > sleepq_wait(void *wchan) > { > MPASS(!(curthread->td_flags & TDF_SINTR)); > mtx_lock_spin(&sched_lock); > sleepq_switch(wchan); ----we sleep here----- some other thread runs, When it wakes up it magicall owns the schedlock which it releases. then it sleeps and locks schedlock again.A ----- we get run.. magically the schedlock is changed so that we own it. now we return, maybe 5 minutes later and must free it. > mtx_unlock_spin(&sched_lock); > } > > sched_lock mutex is held, and sleepq_switch() eventually calls > cpu_switch() which switches to a new thread. > > I don't exactly understand when the sched_lock mutex is released. > > Can someone please help me? > > Thanks, > -shrivatsan > > > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4B8428C7.8010705>