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
[Caml-list] Finalizers and threads
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-12-16 (23:04)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] Finalizers and threads
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