From owner-cvs-all Sun Jul 8 6: 6: 6 2001 Delivered-To: cvs-all@freebsd.org Received: from CPE-61-9-164-106.vic.bigpond.net.au (CPE-61-9-166-74.vic.bigpond.net.au [61.9.166.74]) by hub.freebsd.org (Postfix) with ESMTP id CA60937B414; Sun, 8 Jul 2001 06:05:54 -0700 (PDT) (envelope-from darrenr@reed.wattle.id.au) Received: (from root@localhost) by CPE-61-9-164-106.vic.bigpond.net.au (8.11.0/8.11.0) id f660EKq22289; Fri, 6 Jul 2001 10:14:20 +1000 (EST) From: Darren Reed Message-Id: <200107060014.KAA16514@avalon.reed.wattle.id.au> Subject: Re: cvs commit: src/sys/sys systm.h condvar.h src/sys/kern kern_ In-Reply-To: <20010705174135.A79818@sneakerz.org> from Alfred Perlstein at "Jul 5, 1 05:41:35 pm" To: bright@sneakerz.org (Alfred Perlstein) Date: Fri, 6 Jul 2001 10:14:16 +1000 (EST) Cc: gibbs@scsiguy.com, jhb@FreeBSD.org, jake@FreeBSD.org, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org, dillon@earth.backplane.com, mjacob@feral.com, dfr@nlsystems.com X-Mailer: ELM [version 2.4ME+ PL37 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > * Justin T. Gibbs [010705 17:28] wrote: > > >It happens with SMP, too, not just preemption. The calls are an optimization > > >to avoid problems with releasing the lock after the wakeup. The contention > > >can be avoided if we release the lock before calling wakeup(), but doing that > > >leaves a window open for another CPU to alter the data that the lock protects > > >possibly invalidating the wakeup that then gets sent. > > > > This window exists anyway. The locked mutex it not passed to the woken > > up thread, so there will always be a race between the woken up thread > > acquiring the mutex and some other thread on some other CPU acquiring it > > first and making the wakeup invalid. I would have thought that this paragraph made the solution to the problem obvious - pass a mutex someone along the way. Or you use an interface like solaris has: #include void cv_init(kcondvar_t *cvp, char *name, kcv_type_t type, void *arg); voidcv_destroy(kcondvar_t *cvp); void cv_wait(kcondvar_t *cvp, kmutex_t *mp); void cv_signal(kcondvar_t *cvp); void cv_broadcast(kcondvar_t *cvp); int cv_wait_sig(kcondvar_t *cvp, kmutex_t *mp); clock_t cv_timedwait(kcondvar_t *cvp, kmutex_t *mp, clock_t timeout); clock_t cv_timedwait_sig(kcondvar_t *cvp, kmutex_t *mp, clock_t timeout); The important thing to look for here is a mutex is passed to cv_*wait*(). Obviously the same one should be passed by all callers waiting on a particular signal. Darren To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message