Date: Fri, 17 Sep 2004 00:30:28 +0200 From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: Nate Lawson <nate@root.org> Cc: cvs-all@FreeBSD.org Subject: Re: cvs commit: src/sys/dev/md md.c Message-ID: <20040916223028.GH30151@darkness.comp.waw.pl> In-Reply-To: <414A1073.8010404@root.org> References: <20040916185923.2F92316A552@hub.freebsd.org> <4149EC27.9080200@root.org> <20040916204321.GE30151@darkness.comp.waw.pl> <414A1073.8010404@root.org>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] On Thu, Sep 16, 2004 at 03:15:15PM -0700, Nate Lawson wrote: +> You should be checking the work condition in thread 2 while holding the +> mutex but before going to sleep. Adding work to the queue happens in +> thread 1 where you write "..." and that is done with the mutex held so +> there is no race. The full diagram with this detail included is: +> +> thread1 thread2 +> ----------------------------- +> mtx_lock(mtx) +> add work to queue +> mtx_unlock(mtx) +> mtx_lock(mtx) +> wakeup(ptr) +> check queue for work item +> if (!work item) +> msleep(ptr, mtx) +> else +> dequeue work item and loop +> +> Since the work item is added in thread1 with the mutex held, the check +> for it in thread2 is safe and race-free. A wakeup is only there to +> kickstart thread2 if it's asleep. If it's running, it needs to check +> atomically that there is no work before sleeping. If it doesn't do +> this, it's a bug. Yes, you are right. -- Pawel Jakub Dawidek http://www.FreeBSD.org pjd@FreeBSD.org http://garage.freebsd.pl FreeBSD committer Am I Evil? Yes, I Am! [-- Attachment #2 --] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQFBShQEForvXbEpPzQRAisEAKC2dZwSOQXqam457G3vp6hpsM7+uwCg1M7s 7WL9FYxauNEZtAhWKTcvZGI= =jqiM -----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040916223028.GH30151>
