cvs commit: src/sys/dev/md md.c
Pawel Jakub Dawidek
pjd at FreeBSD.org
Thu Sep 16 15:30:30 PDT 2004
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 at FreeBSD.org http://garage.freebsd.pl
FreeBSD committer Am I Evil? Yes, I Am!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/cvs-src/attachments/20040917/b89fbed0/attachment.bin
More information about the cvs-src
mailing list