From owner-freebsd-arch Sun Sep 24 20:18:49 2000 Delivered-To: freebsd-arch@freebsd.org Received: from smtp03.primenet.com (smtp03.primenet.com [206.165.6.133]) by hub.freebsd.org (Postfix) with ESMTP id 4875937B43F for ; Sun, 24 Sep 2000 20:18:30 -0700 (PDT) Received: (from daemon@localhost) by smtp03.primenet.com (8.9.3/8.9.3) id UAA00568 for ; Sun, 24 Sep 2000 20:17:03 -0700 (MST) Received: from usr05.primenet.com(206.165.6.205) via SMTP by smtp03.primenet.com, id smtpdAAAN1aicb; Sun Sep 24 20:16:51 2000 Received: (from tlambert@localhost) by usr05.primenet.com (8.8.5/8.8.5) id UAA04938 for arch@FreeBSD.ORG; Sun, 24 Sep 2000 20:18:12 -0700 (MST) From: Terry Lambert Message-Id: <200009250318.UAA04938@usr05.primenet.com> Subject: Re: Mutexes and semaphores To: arch@FreeBSD.ORG Date: Mon, 25 Sep 2000 03:18:12 +0000 (GMT) In-Reply-To: <200009241833.LAA00463@vashon.polstra.com> from "John Polstra" at Sep 24, 2000 11:33:23 AM X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > There are plenty of reasonable situations where you have a block of > code (say, a function) and a certain mutex needs to be locked while > it executes. The function might be called from several different > places. Maybe all of the call sites already hold the mutex, and > maybe they don't. Maybe it is hard to say for sure. Maybe new calls > will be added in the future which will add further uncertainty. With > recursive mutexes you can make the code robust by locking the mutex > inside the called function. This robustness is certain and it is > independent of what is going on in the rest of the system. This is evil. You are using a mutex to protect code, when you should be using it to protect data. If you want to protect code, you should use a semaphore, instead. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message