caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yaron Minsky <yminsky@janestreet.com>
To: Markus Mottl <markus.mottl@gmail.com>
Cc: "Török Edwin" <edwin+ml-ocaml@etorok.net>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Threads and "transaction isolation" in OCaml
Date: Fri, 16 Aug 2013 20:06:30 -0400	[thread overview]
Message-ID: <CACLX4jQ7GK2Et=VC42hhjRYiuCh86ZWF5DHTNV1HGReN4BYOAQ@mail.gmail.com> (raw)
In-Reply-To: <CAP_800ouyegVh=srSK5rRXAK56Akk6DBkH5tzSnTQA7jPZHp8A@mail.gmail.com>

I'd like to second Markus' request here.  We definitely take advantage
of this behavior in the compiler, and I hadn't realized that it didn't
hold in byte-code.  I do think this is a rather valuable hack, and it
would be good to make the bounds of its applicability more explicit.

y

On Fri, Aug 16, 2013 at 12:07 PM, Markus Mottl <markus.mottl@gmail.com> wrote:
> On Fri, Aug 16, 2013 at 4:46 AM, Török Edwin <edwin+ml-ocaml@etorok.net> wrote:
>> I wrote a little test program and this is not true for bytecode -vmthread, but seems to work for bytecode -thread and native -thread:
>
> Thanks for this example.  It's not surprising that this trick does not
> work with VM-threads, but I have never seen anybody use them for
> anything so I'm not bothered by this.
>
> But, surprisingly to me, I did manage to get a failure with byte code
> + POSIX threads when running this example on Linux (Centos 6.4) via
> VMware Fusion (Mac OS X).  I admittedly have never thoroughly tested
> these "transactions" with any sort of byte code, since I practically
> exclusively run native code.  Still, I would have expected the runtime
> to work identically here.  Interestingly, I couldn't replicate the
> error on a VPS running the same OS and compiler, but using Xen (via
> Linode) instead of VMware Fusion for virtualization.
>
> Note that some open source libraries, e.g. the Nano_mutex module in
> Jane Street Core, depend on this trick so it seems important to figure
> out how safe and portable it really is.  It would be a huge pity to do
> without, since it can offer quite dramatic performance improvements
> for certain applications.
>
> Does anybody know a reason why byte code + POSIX threads might fail
> with this trick?
>
>> I'd consider this very fragile as you'd need to know the implementation details of every function you call (or only calling your own safe functions). I was surprised to find out that even Array.fold_left creates a temporary ref for example.
>
> It would certainly be unwise to call any function whose implementation
> is not fixed and fully understood wrt. transaction isolation.  This
> trick is obviously low-level and its use should be clearly documented
> by the developer.  Most of the time it will only consist of a few
> assignments or pattern-matches anyway.
>
> Regards,
> Markus
>
> --
> Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com
>
> --
> 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

  reply	other threads:[~2013-08-17  0:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-15 21:57 Markus Mottl
2013-08-16  1:28 ` John F Carr
2013-08-16  2:55   ` Markus Mottl
2013-08-16  8:46 ` Török Edwin
2013-08-16 16:07   ` Markus Mottl
2013-08-17  0:06     ` Yaron Minsky [this message]
2013-08-19  6:10       ` Mark Shinwell
2013-08-19 14:18         ` Markus Mottl
2013-08-19  7:33     ` Xavier Leroy

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='CACLX4jQ7GK2Et=VC42hhjRYiuCh86ZWF5DHTNV1HGReN4BYOAQ@mail.gmail.com' \
    --to=yminsky@janestreet.com \
    --cc=caml-list@inria.fr \
    --cc=edwin+ml-ocaml@etorok.net \
    --cc=markus.mottl@gmail.com \
    /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).