caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Long running finalizers and global lock
@ 2011-04-05 17:10 Pedro Borges
  2011-04-06 15:20 ` Goswin von Brederlow
  2011-04-07 12:05 ` Damien Doligez
  0 siblings, 2 replies; 3+ messages in thread
From: Pedro Borges @ 2011-04-05 17:10 UTC (permalink / raw)
  To: caml-list

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Long running finalizers and global lock
  2011-04-05 17:10 [Caml-list] Long running finalizers and global lock Pedro Borges
@ 2011-04-06 15:20 ` Goswin von Brederlow
  2011-04-07 12:05 ` Damien Doligez
  1 sibling, 0 replies; 3+ messages in thread
From: Goswin von Brederlow @ 2011-04-06 15:20 UTC (permalink / raw)
  To: Pedro Borges; +Cc: caml-list

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Long running finalizers and global lock
  2011-04-05 17:10 [Caml-list] Long running finalizers and global lock Pedro Borges
  2011-04-06 15:20 ` Goswin von Brederlow
@ 2011-04-07 12:05 ` Damien Doligez
  1 sibling, 0 replies; 3+ messages in thread
From: Damien Doligez @ 2011-04-07 12:05 UTC (permalink / raw)
  To: caml users


On 2011-04-05, at 19:10, Pedro Borges wrote:

> I have a long running function inse a finalizer is it safe to release
> and acquire the runtime lock ?


NOT safe.  In fact, it will almost certainly crash immediately.

-- Damien


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-04-07 12:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-05 17:10 [Caml-list] Long running finalizers and global lock Pedro Borges
2011-04-06 15:20 ` Goswin von Brederlow
2011-04-07 12:05 ` Damien Doligez

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).