caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Chet Murthy <murthy.chet@gmail.com>
To: Xavier Leroy <Xavier.Leroy@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] recursive mutexes in ocaml
Date: Wed, 17 Jul 2013 10:50:42 -0700	[thread overview]
Message-ID: <2474292.A2ICsWKU9J@groupon> (raw)
In-Reply-To: <51E6D575.9010406@inria.fr>


Xavier,

Wow, that's excellent.  Made my morning!  I've implemented Java's
monitors, so yeah, they're as you describe, and I cannot imagine doing
it any other way.  What were they -thinkin'- in the POSIX committee?

Ah, well.

OK.  I'll just add the (few) lines of code needed to get basic
recursive mutexes for locking purposes, and leave it at that.  Given
Butenhof's analysis, I -fully- agree with leavin' 'em out of ocaml.
Yikes!

--chet--

On Wednesday, July 17, 2013 07:33:41 PM Xavier Leroy wrote:
> Hi Chet,
> 
> > I figured I'd ask -why- ocaml's mutexes aren't recursive.  Or at
> > least, why there isn't an option for recursive mutexes?
> 
> Dave Butenhof, one of the main authors of POSIX threads, makes rather
> strong points against recursive mutexes:
> http://tinyurl.com/butenhof-recursive-mutexes
> 
> The killer issue in my opinion is how to make recursive mutexes play
> well with pthread_cond_wait() / Condition.wait: POSIX's
> pthread_cond_wait() only releases the mutex once, which leads to all
> sorts of deadlock if it's been acquired N>1 times.  I believe Java
> has a more useful behavior, whereas the mutex is released N times,
> then reacquired N times.  But this cannot be implemented easily on top
> of POSIX threads.  And don't get me started on Win32 threads...
> 
> It might make sense to have recursive mutexes as a separate type,
> different from ordinary mutexes, so that it's not usable in
> conjunction with Condition.wait.  Apparently, Batteries has/had that.
> 
> - Xavier Leroy

      reply	other threads:[~2013-07-17 17:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-12 19:59 [Caml-list] sources for ZINC? Nicolas Ojeda Bar
2013-07-16  2:39 ` [Caml-list] " Hongbo Zhang
2013-07-16 15:33 ` [Caml-list] " Xavier Leroy
2013-07-16 17:06   ` Benedikt Meurer
2013-07-16 19:54     ` Ashish Agarwal
2013-07-17  7:28       ` [Caml-list] recursive mutexes in ocaml Chet Murthy
2013-07-17 10:54         ` Gerd Stolpmann
2013-07-17 15:33           ` Edgar Friendly
2013-07-17 17:33         ` Xavier Leroy
2013-07-17 17:50           ` Chet Murthy [this message]

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

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

  git send-email \
    --in-reply-to=2474292.A2ICsWKU9J@groupon \
    --to=murthy.chet@gmail.com \
    --cc=Xavier.Leroy@inria.fr \
    --cc=caml-list@inria.fr \
    /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 NNTP newsgroup(s).