From owner-freebsd-arch Mon Sep 25 15:35:55 2000 Delivered-To: freebsd-arch@freebsd.org Received: from smtp02.primenet.com (smtp02.primenet.com [206.165.6.132]) by hub.freebsd.org (Postfix) with ESMTP id 6D2AC37B424 for ; Mon, 25 Sep 2000 15:35:52 -0700 (PDT) Received: (from daemon@localhost) by smtp02.primenet.com (8.9.3/8.9.3) id PAA22718; Mon, 25 Sep 2000 15:32:57 -0700 (MST) Received: from usr07.primenet.com(206.165.6.207) via SMTP by smtp02.primenet.com, id smtpdAAAc1aqhS; Mon Sep 25 15:32:38 2000 Received: (from tlambert@localhost) by usr07.primenet.com (8.8.5/8.8.5) id PAA07367; Mon, 25 Sep 2000 15:35:28 -0700 (MST) From: Terry Lambert Message-Id: <200009252235.PAA07367@usr07.primenet.com> Subject: Re: Mutexes and semaphores (was: cvs commit: src/sys/conf files To: arch@freebsd.org Date: Mon, 25 Sep 2000 22:35:28 +0000 (GMT) Cc: tlambert@primenet.com In-Reply-To: <200009252024.NAA02690@vashon.polstra.com> from "John Polstra" at Sep 25, 2000 01:24:54 PM 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 > > Counting semaphores are a more appropriate primitive, as the > > "resource" which is counted is the ownership capability. As > > others have pointed out (Archie, etc.), a semaphore with a > > count of 1 is appropriate. When the count goes 1->0, then > > we can consider that ownership has been relinquished. > > Actually, when the count goes 1->0, ownership has been acquired, not > relinquished. The count represents the number of available units, > and that is the case in every definition and every implementation of > semaphores I have ever seen (which is quite a few, beginning in the > early 70's.). It's even true in the rather baroque implementation of > semop(3). Remaining resources vs. acquired resources. Same difference, you knew what I meant, which is what mattered. > Fine, then you don't need a counting semaphore at all, as a simple > non-recursive mutex will do the same job just as well and more > efficiently. Fine. Then we're agreed: non-recursive mutexes are the base unit, and recursion will be implemented on a case by case basis using an additional structure, which contains a non-recursive mutex, a recursion counter, and an owner field. Glad that's settled, until the first time a thread migrates between processors, and we decide we need a semaphore instead of a mutex as a primitive in order to handle sleeps and wakeups that occur with a mutex with a recursion count greater than 0, for some ungodly reason. 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