unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Rob Browning <rlb@defaultvalue.org>
Cc: guile-devel@gnu.org
Subject: Re: Recursive mutexes?
Date: Sat, 26 Oct 2002 17:16:06 -0500	[thread overview]
Message-ID: <87hef86e3d.fsf@raven.i.defaultvalue.org> (raw)
In-Reply-To: <87r8edos41.fsf@zagadka.ping.de> (Marius Vollmer's message of "26 Oct 2002 22:35:58 +0200")

Marius Vollmer <mvo@zagadka.ping.de> writes:

> Our current coop mutexes are not 'recursive'.  This means that a
> thread blocks when it tries to lock a mutex that it already has
> locked.
>
> I think we should make our mutexes be recursive by default.  Expecting
> to block when locking a mutex that is already lcoked by one self is
> not very useful, since no one can unlock that mutex (excepts asyncs).

Though people coming from POSIX threads (at least under glibc) will be
used to having to explicitly ask for recursive mutexes, and at least
at the C level, there's apparently an efficiency issue involved.
Would it be hard to provide both and let the user select at creation
time?

> The only good argument against recursive mutexes that I can think of
> is a tiny performance gain since you don't need to do some checking.

I guess to some extent it would depend on how tiny the gain would be :>

> SRFI-18 specifies non-recursive mutexes and allows non-owning threads
> to unlock a mutex.  Such uses of a mutex are, in my view, a mockery of
> condition variables should be avoided.

Well you certainly could use a condition variable instead of a mutex
here, but I would suspect that in cases where you just want to wake
someone else up, a mutex others can unlock would be lighter weight.
With a condition variable you have to have both a mutex and the
condition variable.

It sounds like the SRFI-18 mutexes are just POSIX Semaphores with one
token, and POSIX Semaphores are more flexible, and seem only trivially
harder to implement -- likely not much more than adding an integer
counter and a few trivial numeric comparisons.  If so, I'd rather have
a POSIX Semaphore and provide a trivial wrapper that satisfies
SRFI-18.

In POSIX mutexes are pretty low-level -- they're more or less just an
atomic lock -- that makes sense since they're the simplest portable
sync type.  Semaphores and Condition Variables are for anything more
than the most basic operations, and even there (as you and I talked
about), there are no FIFO fairness guarantees, so you're often faced
with building your own sync operations on top of them.

One thing that the POSIX model has going for it is exposure -- I
suspect a lot of people are familiar with how the API works, so my
default inclination would be to follow that API whenever there's not a
good reason not to.  We may also want to add some enhancements like
FIFO guarantees that don't contradict the standard, but that's a
separate question.

IMO thread programming is hard.  Writing correct algorithms using
threads can be hard, and if someone already has something they've
written using the POSIX semantics that works, it will be a lot easier
to migrate to another language if the semantics are similar.

-- 
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG=1C58 8B2C FB5E 3F64 EA5C  64AE 78FE E5FE F0CB A0AD


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


  parent reply	other threads:[~2002-10-26 22:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-26 20:35 Recursive mutexes? Marius Vollmer
2002-10-26 21:39 ` Neil Jerram
2002-10-27  0:03   ` Marius Vollmer
2002-10-27  1:20     ` Thomas Bushnell, BSG
2002-10-27 12:36       ` Marius Vollmer
2002-10-27  7:55     ` Neil Jerram
2002-10-27 18:33       ` Rob Browning
2002-10-26 22:16 ` Rob Browning [this message]
2002-10-26 22:29   ` Rob Browning
2002-10-26 22:42   ` Tom Lord
2002-10-26 23:26     ` Thomas Bushnell, BSG
2002-10-26 23:35       ` Tom Lord
2002-10-26 23:50         ` Tom Lord
2002-10-27  1:18           ` Thomas Bushnell, BSG
2002-10-26 22:47   ` Tom Lord
2002-10-27  8:33     ` Neil Jerram
2002-10-27 17:21       ` Tom Lord
2002-10-27  0:35   ` Marius Vollmer
2002-10-27  4:36     ` Rob Browning
2002-10-27 11:32       ` Marius Vollmer
2002-10-27 18:44         ` Rob Browning

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hef86e3d.fsf@raven.i.defaultvalue.org \
    --to=rlb@defaultvalue.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).