From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 5B8BD7ED25 for ; Wed, 17 Jul 2013 17:33:04 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of thelema314@gmail.com) identity=pra; client-ip=209.85.214.42; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="thelema314@gmail.com"; x-sender="thelema314@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of thelema314@gmail.com designates 209.85.214.42 as permitted sender) identity=mailfrom; client-ip=209.85.214.42; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="thelema314@gmail.com"; x-sender="thelema314@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-bk0-f42.google.com) identity=helo; client-ip=209.85.214.42; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="thelema314@gmail.com"; x-sender="postmaster@mail-bk0-f42.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsMBAAm45lHRVdYqk2dsb2JhbABSCIM6UIMGrSWJaog9gQgIFg4BAQEBBwsLCRQEJIIjAQEEASMdARsSCwEDAQkCBgMCCwMXHQICGwcBEQEFAQoSBhMSh2sBAwkGDIh+j0GMAE+Cf4RFChknAwpkh3QBBQQIjiYGDIEyBAeCWoEhA5dcgSmOPxYphFQggTU X-IPAS-Result: AsMBAAm45lHRVdYqk2dsb2JhbABSCIM6UIMGrSWJaog9gQgIFg4BAQEBBwsLCRQEJIIjAQEEASMdARsSCwEDAQkCBgMCCwMXHQICGwcBEQEFAQoSBhMSh2sBAwkGDIh+j0GMAE+Cf4RFChknAwpkh3QBBQQIjiYGDIEyBAeCWoEhA5dcgSmOPxYphFQggTU X-IronPort-AV: E=Sophos;i="4.89,685,1367964000"; d="scan'208";a="21481173" Received: from mail-bk0-f42.google.com ([209.85.214.42]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Jul 2013 17:33:03 +0200 Received: by mail-bk0-f42.google.com with SMTP id jk13so807247bkc.29 for ; Wed, 17 Jul 2013 08:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ieAAYG9ObbCCUVP60qlvauHrKHn2vB+hDhT41oNlG0s=; b=0KKTezDiKzGXu3gdqOLLl/ARBS//5Eu0UiF8gw5pM/GU54zH6o5Ylgqp9266Q/9eIV n3/dldsIlmByBoNTCHMkIVpb9OYIHMorUXg9QT/eqfdhrY5OFw3InQSuA/XhkSTeVkGD Y5tfy1nfIw9O2sOR/3DhJj/JiJqsk4CRTJlqckA6E8jg8OUHyv+uTtdDAx1lFsGH37Y7 ILTLnsrBanMSddiij+09LSJET+1agFI8ItWrH98FMHqLjKTsty7jBN1nuI8hQ29CGA9B ogCrRRThJPbK0JPIaWn6haONTUCY1skwXNgdUOgXus/FdsFoIpvDLosI37g6EQdhVKfu tcXw== MIME-Version: 1.0 X-Received: by 10.204.198.9 with SMTP id em9mr1094738bkb.131.1374075182906; Wed, 17 Jul 2013 08:33:02 -0700 (PDT) Received: by 10.205.112.12 with HTTP; Wed, 17 Jul 2013 08:33:02 -0700 (PDT) In-Reply-To: <1374058447.21437.37.camel@zotac> References: <5000924.vCd1HWCNpc@groupon> <1374058447.21437.37.camel@zotac> Date: Wed, 17 Jul 2013 11:33:02 -0400 Message-ID: From: Edgar Friendly To: Gerd Stolpmann Cc: Chet Murthy , caml-list Content-Type: multipart/alternative; boundary=485b3970d6062c405f04e1b6cf4e Subject: Re: [Caml-list] recursive mutexes in ocaml --485b3970d6062c405f04e1b6cf4e Content-Type: text/plain; charset=UTF-8 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 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 > --485b3970d6062c405f04e1b6cf4e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
There was some back and forth on the batteries-devel maili= ng list about getting rid of BatRMutex, batteries' implementation of re= cursive mutexes(search the archives). =C2=A0They're still in, if you wa= nt 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 sch= rieb Chet Murthy:
> Recently I'm writing some multi-threaded code, a= nd ended up wishing I
> had recursive mutexes. =C2=A0Now .... I realize that this is a simple = thing
> to "get" -- just hack the code, maaaan. =C2=A0But before (or= , erm
> .... whilst) I do that, I figured I'd ask -why- ocaml's mutexe= s aren't
> recursive. =C2=A0Or at least, why there isn't an option for recurs= ive
> 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. =C2=A0That 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? =C2=A0Or is it just a matter of taste?

The multi-threading feature in ocaml is quite old. I guess there was<= br> 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. Th= ere has
> =C2=A0 =C2=A0never been a case in numerous complex bindings where I wo= uld have
> =C2=A0 =C2=A0needed this feature. In mission-critical code I even pref= er
> =C2=A0 =C2=A0error-checking mutexes that prevent me from acquiring loc= ks twice
> =C2=A0 =C2=A0or releasing them once too often. As with everything mult= ithreaded:
> =C2=A0 =C2=A0the simpler the better. It's hard enough to reason ab= out the simple
> =C2=A0 =C2=A0case.
>
> and this is about the ocaml master lock. =C2=A0But it's the only i= nstance I
> find of somebody discussing recursive mutexes in ocaml.
>
>
>

--
------------------------------------------------------------
Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany
gerd@gerd-stolpmann.de =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0http://www.gerd-stolpmann.de
Phone: +49-6151-153855 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0Fax: +49-6151-997714
------------------------------------------------------------



--
Caml-list mailing list. =C2=A0Subscription management and archives:
ht= tps://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

--485b3970d6062c405f04e1b6cf4e--