From owner-cvs-all@FreeBSD.ORG Sat Sep 18 02:36:07 2004 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F243116A4CF for ; Sat, 18 Sep 2004 02:36:06 +0000 (GMT) Received: from mail4.speakeasy.net (mail4.speakeasy.net [216.254.0.204]) by mx1.FreeBSD.org (Postfix) with ESMTP id BB98943D53 for ; Sat, 18 Sep 2004 02:36:06 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: (qmail 757 invoked from network); 18 Sep 2004 02:36:06 -0000 Received: from dsl027-160-063.atl1.dsl.speakeasy.net (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) encrypted SMTP for ; 18 Sep 2004 02:36:06 -0000 Received: from slimer.baldwin.cx (slimer.baldwin.cx [192.168.0.16]) (authenticated bits=0) by server.baldwin.cx (8.12.11/8.12.11) with ESMTP id i8I2a0OI004409; Fri, 17 Sep 2004 22:36:03 -0400 (EDT) (envelope-from jhb@FreeBSD.org) From: John Baldwin To: Nate Lawson Date: Fri, 17 Sep 2004 21:23:30 -0400 User-Agent: KMail/1.6.2 References: <20040916204321.GE30151@darkness.comp.waw.pl> <200409162152.41670.jhb@FreeBSD.org> <414A4A79.8060101@root.org> In-Reply-To: <414A4A79.8060101@root.org> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200409172123.30503.jhb@FreeBSD.org> X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on server.baldwin.cx cc: scottl@samsco.org cc: src-committers@FreeBSD.org cc: pjd@FreeBSD.org cc: cvs-src@FreeBSD.org cc: cvs-all@FreeBSD.org cc: "M. Warner Losh" Subject: Re: cvs commit: src/sys/dev/md md.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Sep 2004 02:36:07 -0000 On Thursday 16 September 2004 10:22 pm, Nate Lawson wrote: > John Baldwin wrote: > > On Thursday 16 September 2004 08:59 pm, M. Warner Losh wrote: > >>In message: <414A109E.4080601@samsco.org> > >> > >> Scott Long writes: > >>: Or just use a semaphore. > >> > >>Or a condition variable. > > > > That doesn't help, a condition variable doesn't have state like a > > semaphore. The correct fix is to do this: > > > > thread A > > ---------- > > mtx_lock(); > > adjust_state(); > > mtx_unlock(); > > wakeup(); > > > > thread B > > --------- > > mtx_lock(); > > while (state_still_needs_sleep()) > > msleep(...) > > mtx_unlock() > > > > Proving that there is no race is left as an exercise to the reader. :) > > Isn't this exactly what I said? You use if instead of while. Truly pedantic coding would use while instead. :) I'm not aware of any bugs in our current wakeup or condition variable implementations that would lead to spurious wakeups, but you never know (esp. with wakeup where the same thing gets slept on for 47 different reasons, e.g. the proc pointer) when you might get a wakeup that's really not for you. Best to make sure that if you do you don't break. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org