cvs commit: src/sys/compat/ndis subr_ntoskrnl.c

John Baldwin jhb at freebsd.org
Mon Jul 23 19:55:37 UTC 2007


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


More information about the cvs-src mailing list