English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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-06 (18:01)
From: Dr. Thomas Fischbacher <t.fischbacher@s...>
Subject: Re: [Caml-list] Custom blocks and finalization


> Neither of the above will ever trigger a garbage collection, but they
> are still prohibited.
So, I ask: Why? Unregistering a global root evidently does not trigger a GC,
and starting a GC from within a C-registered custom
hasher/finalizer/comparer/serializer/etc is the one specific thing that
according to the docs causes trouble, so I don't really see why I should go
through quite a fair bit of our codebase to come up with a fix to something
which as far as I can see must not be a problem.

> It certainly doesn't, but it obviously manipulates runtime
> datastructures which may not necessarily be in a state during
> finalization where this is safe.  I'd have to study the runtime code
> in detail to learn more, but maybe the OCaml team can clarify this
> issue more quickly?

Yes, clarification would be much appreciated. I still maintain that my
use of caml_remove_global_root() in a finalizer is not in violation of 
this spec:

  Note: the finalize, compare, hash, serialize and deserialize functions
attached to custom block descriptors must never trigger a garbage 
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 

So, if there is a problem with this practice, it is certainly an OCaml 
bug (i.e. spec
not matching behaviour) and should be fixed by the OCaml team.

best regards,
Thomas Fischbacher