Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Sep 2000 13:24:54 -0700 (PDT)
From:      John Polstra <jdp@polstra.com>
To:        arch@freebsd.org
Cc:        tlambert@primenet.com
Subject:   Re: Mutexes and semaphores (was: cvs commit: src/sys/conf files
Message-ID:  <200009252024.NAA02690@vashon.polstra.com>
In-Reply-To: <200009252006.NAA00200@usr02.primenet.com>
References:  <200009252006.NAA00200@usr02.primenet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <200009252006.NAA00200@usr02.primenet.com>,
Terry Lambert  <tlambert@primenet.com> wrote:
> > You are wrong.  Counting semaphores do not keep track of owners.
> 
> OK.  Let's be pedantic.  Neither do mutexes.

I didn't say "mutex", I said "recursive mutex".  Recursive mutexes
do indeed keep track of their owners.

> 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).

> I never stated that the recursion count would be implemented in
> the semaphore count of a counting semaphore.  Please read the
> first quoted sentence again.  Ownership and recursion are kept
> in the seperate struct.

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.

> To get around this, you have to implement non-recusing mutexes
> using a semaphore of count 1.

A semaphore with a count of 1, when used for mutual exclusion,
behaves exactly the same as a simple mutex.  I don't understand why
you brought up counting semaphores at all.

John
-- 
  John Polstra                                               jdp@polstra.com
  John D. Polstra & Co., Inc.                        Seattle, Washington USA
  "Disappointment is a good sign of basic intelligence."  -- Chögyam Trungpa



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200009252024.NAA02690>