From owner-cvs-src@FreeBSD.ORG Thu Sep 16 22:30:30 2004 Return-Path: Delivered-To: cvs-src@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 578A016A4CE; Thu, 16 Sep 2004 22:30:30 +0000 (GMT) Received: from darkness.comp.waw.pl (darkness.comp.waw.pl [195.117.238.136]) by mx1.FreeBSD.org (Postfix) with ESMTP id F2DEF43D53; Thu, 16 Sep 2004 22:30:29 +0000 (GMT) (envelope-from pjd@darkness.comp.waw.pl) Received: by darkness.comp.waw.pl (Postfix, from userid 1009) id B5729ACAFE; Fri, 17 Sep 2004 00:30:28 +0200 (CEST) Date: Fri, 17 Sep 2004 00:30:28 +0200 From: Pawel Jakub Dawidek To: Nate Lawson Message-ID: <20040916223028.GH30151@darkness.comp.waw.pl> References: <20040916185923.2F92316A552@hub.freebsd.org> <4149EC27.9080200@root.org> <20040916204321.GE30151@darkness.comp.waw.pl> <414A1073.8010404@root.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="e+hDQL8ScHtmKSgz" Content-Disposition: inline In-Reply-To: <414A1073.8010404@root.org> User-Agent: Mutt/1.4.2i X-PGP-Key-URL: http://people.freebsd.org/~pjd/pjd.asc X-OS: FreeBSD 5.2.1-RC2 i386 cc: cvs-src@FreeBSD.org cc: src-committers@FreeBSD.org cc: cvs-all@FreeBSD.org Subject: Re: cvs commit: src/sys/dev/md md.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Sep 2004 22:30:30 -0000 --e+hDQL8ScHtmKSgz Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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= =20 +> mutex but before going to sleep. Adding work to the queue happens in=20 +> thread 1 where you write "..." and that is done with the mutex held so= =20 +> there is no race. The full diagram with this detail included is: +>=20 +> 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 +>=20 +> Since the work item is added in thread1 with the mutex held, the check= =20 +> for it in thread2 is safe and race-free. A wakeup is only there to=20 +> kickstart thread2 if it's asleep. If it's running, it needs to check=20 +> atomically that there is no work before sleeping. If it doesn't do=20 +> this, it's a bug. Yes, you are right. --=20 Pawel Jakub Dawidek http://www.FreeBSD.org pjd@FreeBSD.org http://garage.freebsd.pl FreeBSD committer Am I Evil? Yes, I Am! --e+hDQL8ScHtmKSgz Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQFBShQEForvXbEpPzQRAisEAKC2dZwSOQXqam457G3vp6hpsM7+uwCg1M7s 7WL9FYxauNEZtAhWKTcvZGI= =jqiM -----END PGP SIGNATURE----- --e+hDQL8ScHtmKSgz--