caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: Pedro Borges <pdhb.lists@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Long running finalizers and global lock
Date: Wed, 06 Apr 2011 17:20:34 +0200	[thread overview]
Message-ID: <87ipurbe4d.fsf@frosties.localnet> (raw)
In-Reply-To: <BANLkTin4PqRfVncz1r+JquTr9zYJXGi_+g@mail.gmail.com> (Pedro Borges's message of "Tue, 5 Apr 2011 18:10:39 +0100")

Pedro Borges <pdhb.lists@gmail.com> writes:

> Hi again,
>
> the reference manual states:
>
>  > Note: the finalize, compare, hash, serialize and deserialize
> functions attached to custom block
>  > descriptors must never trigger a garbage collection. Within these
> functions, do not call any of
>  > the Caml allocation functions, and do not perform a callback into
> Caml code. Do not use
>  > CAMLparam to register the parameters to these functions, and do not
> use CAMLreturn to return the result.
>
> I have a long running function inse a finalizer is it safe to release
> and acquire the runtime lock ?
>
> Best Regards

If you release the lock then any ocaml values might get relocated by the
GC at any time and then your code would reference the wrong address. If
your code uses any ocaml values (CAMLparam or CAMLlocal or registered
roots) you will need to aquire the lock every time you access
them.

On the other hand I'm not sure it is allowed to release the lock in a
finalizer. Given the warning the GC seems to be in an inconsitent state
when the finalizer is run and releasing the lock would mean some other
thread would certinly allocate something and crash your program.

So overall I consider it highly unlikely. Say I'm 99% sure you can't
release the lock but I would be happy to be tought otherwise.

MfG
        Goswin

  reply	other threads:[~2011-04-06 15:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-05 17:10 Pedro Borges
2011-04-06 15:20 ` Goswin von Brederlow [this message]
2011-04-07 12:05 ` Damien Doligez

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=87ipurbe4d.fsf@frosties.localnet \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    --cc=pdhb.lists@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).