From owner-freebsd-drivers@FreeBSD.ORG Mon Nov 24 20:42:04 2008 Return-Path: Delivered-To: freebsd-drivers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9EF241065689 for ; Mon, 24 Nov 2008 20:42:04 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (bsdimp.com [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id 4B9238FC12 for ; Mon, 24 Nov 2008 20:42:04 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from localhost (localhost [127.0.0.1]) by harmony.bsdimp.com (8.14.2/8.14.1) with ESMTP id mAOKf8iD040496; Mon, 24 Nov 2008 13:41:08 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Mon, 24 Nov 2008 13:42:36 -0700 (MST) Message-Id: <20081124.134236.723203643.imp@bsdimp.com> To: huntting@glarp.com From: "M. Warner Losh" In-Reply-To: <200811241911.mAOJBVkM067002@antediluvian.glarp.com> References: <20081124.103816.1649771647.imp@bsdimp.com> <200811241911.mAOJBVkM067002@antediluvian.glarp.com> X-Mailer: Mew version 5.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: freebsd-drivers@FreeBSD.org Subject: Re: mutex quandry X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Nov 2008 20:42:04 -0000 In message: <200811241911.mAOJBVkM067002@antediluvian.glarp.com> Brad Huntting writes: : The combination of checking sc_running and incrementing sc_inuse : needs to be atomic (hence a mutex around them) but at some point : detach() has to destroy the mutex but my code may still need to use : it. Your solution to this is to make sure that never happens. Anything else is really racy. If you are destroying your mutex and allowing detach to return, the entire sc is freed, so you're dead from that anyway... Warner