Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Custom blocks and finalization
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-05-08 (13:48)
From: Markus Mottl <markus.mottl@g...>
Subject: Re: [Caml-list] Custom blocks and finalization
On Fri, May 8, 2009 at 05:36, Xavier Leroy <> wrote:
> I foresee absolutely no problems with registering/unregistering global
> roots from a C finalizer.  As the manual states, the big no-no in
> C functions attached to custom blocks is allocating in the heap,
> either directly or via a callback into Caml or by releasing the global
> lock.  Within a finalizer, you should also refrain from raising an
> exception, as this would leave the GC is a bizarre state.  But global
> roots operations are OK.

Thanks, good to know.  I had only taken a superficial look at the
implementation and didn't see any problem with global roots, but even
if this might be true now, I wasn't sure whether this would remain so
in the future.

> As for not using the CAMLparam, etc macros in these functions: since
> these functions must not allocate, the macros are certainly not
> needed.  I don't think that actually using them could cause a problem,
> but that would be silly anyway, so don't use them in this context.

Right, since allocations are prohibited anyway, one doesn't need to
protect the passed value and won't need local roots.  I guess the
documentation could still be clarified in this respect, because the
explicit prohibition of using the local root (de)registration
functions suggests that these operations are not guaranteed to be
sound and that this might also extend to global roots.


Markus Mottl