Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: John F Carr <jfc@MIT.EDU>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Threads and "transaction isolation" in OCaml
Date: Thu, 15 Aug 2013 21:28:26 -0400	[thread overview]
Message-ID: <20130815212826.7sz760lhs0c00k84@webmail.mit.edu> (raw)
In-Reply-To: <CAP_800r3q72mPT4L9onnvBL6X0CD63F9f-7t=GVA7GcFMrD3vw@mail.gmail.com>

Do you mean allocation or garbage collection?

Generational garbage collectors can collect without allocation when you 
assign a
young object to a field of an older object.  There is (or may be) a list of
intergenerational (older to younger) references.  When that list exceeds a
threshold, the GC may do a minor collection.

I have not checked what the current implementation of OCaml does in this case.

let x = ref (ref 0) in
let y = ref 1 in (* allocation triggers GC; x is old and y is young *)
... work here ...
x := y (* may cause GC *)


> Hi,
>
> I just wondered how much we can rely on current OCaml-semantics where
> context-switches are impossible as long as there are no allocations.
>
> E.g. pattern-matches, array and record field assignments, etc., can be
> safely chained together in one "transaction" without having to fear
> that another thread will interrupt them.  This is extremely useful for
> optimizing certain applications where lock acquisitions might just be
> too expensive.
>
> There already are some corner cases where things may be
> platform-dependent, e.g. calling functions tail-recursively that take
> more arguments than there are available CPU-registers.  In that case
> the compiler may pass arguments by allocating blocks on the heap.  But
> I think people that care about such obviously brittle semantics know
> where to be careful.
>
> Anyway, is it considered reasonably future-safe to write code of that
> sort?  I'd rather not have new compiler optimizations, etc., interfere
> with these assumptions in the near future.
>
> 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-16  1:28 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 [this message]
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
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=20130815212826.7sz760lhs0c00k84@webmail.mit.edu \
    --to=jfc@mit.edu \
    --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