There was some back and forth on the batteries-devel mailing list about getting rid of BatRMutex, batteries' implementation of recursive mutexes(search the archives).  They're still in, if you want to use them.

E.


On Wed, Jul 17, 2013 at 6:54 AM, Gerd Stolpmann <info@gerd-stolpmann.de> wrote:
Am Mittwoch, den 17.07.2013, 00:28 -0700 schrieb Chet Murthy:
> Recently I'm writing some multi-threaded code, and ended up wishing I
> had recursive mutexes.  Now .... I realize that this is a simple thing
> to "get" -- just hack the code, maaaan.  But before (or, erm
> .... whilst) I do that, I figured I'd ask -why- ocaml's mutexes aren't
> recursive.  Or at least, why there isn't an option for recursive
> mutexes?
>
> I realize that at some level, you can -always- eschew recursive
> mutexes by passing along extra parameters so that code can know
> whether it's locked a particular mutex.  That said, it's (more than) a
> bit of a pain, and surely complicates code ....
>
> Is there some other -reason- that recursive mutexes aren't
> implemented?  Or is it just a matter of taste?

The multi-threading feature in ocaml is quite old. I guess there was
some motivation to keep it as simple as possible, e.g. for maximizing
portability, so you can also build ocaml on an OS that does not support
such fancy features. Nowadays the OS landscape is quite different, of
course, and such frugality can be seen as limitation.

The demand for recursive mutexes is certainly low, because you can
easily have your own little wrapper around Mutex to get them (there is
normally an easy way to recognize the owner). It's just a counter after
all. But yes, having this directly in Mutex would make it simpler. Maybe
file a wish in the bugtracker?

Gerd


>
> Thanks,
> --chet--
>
> P.S. I found Markus' email about this:
>
> >> I'd consider recursive lock acquisitions bad practice. There has
>    never been a case in numerous complex bindings where I would have
>    needed this feature. In mission-critical code I even prefer
>    error-checking mutexes that prevent me from acquiring locks twice
>    or releasing them once too often. As with everything multithreaded:
>    the simpler the better. It's hard enough to reason about the simple
>    case.
>
> and this is about the ocaml master lock.  But it's the only instance I
> find of somebody discussing recursive mutexes in ocaml.
>
>
>

--
------------------------------------------------------------
Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------



--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs