caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Damien Doligez <damien.doligez@inria.fr>
To: OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Finalizers and threads
Date: Wed, 17 Dec 2003 00:05:19 +0100	[thread overview]
Message-ID: <519CE544-301C-11D8-9FCB-00039310CAE8@inria.fr> (raw)
In-Reply-To: <20031212155808.GB23087@fichte.ai.univie.ac.at>

On Friday, December 12, 2003, at 04:58 PM, Markus Mottl wrote:

> I'd like to know whether it is safe to use "enter_blocking_section"
> in finalization functions (C) to allow execution of other threads when
> some operation there (e.g. shutting down some TCP/IP-connection) may
> block for some time.

It is not safe.  The finalization function is called right in the
middle of the GC, and executing some ML code at that point, even in
another thread, is going to result in a disaster.

I guess you should defer the blocking operations by pushing them into
a queue, and perform them after the GC is done (or in another thread).

Note that the contents of the finalized block itself is destroyed as
soon as your finalization function returns, so you should make a copy
of the data you need.

-- Damien

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      reply	other threads:[~2003-12-16 23:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-12 15:58 Markus Mottl
2003-12-16 23:05 ` Damien Doligez [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=519CE544-301C-11D8-9FCB-00039310CAE8@inria.fr \
    --to=damien.doligez@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).