caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Finalizers and threads
@ 2003-12-12 15:58 Markus Mottl
  2003-12-16 23:05 ` Damien Doligez
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Mottl @ 2003-12-12 15:58 UTC (permalink / raw)
  To: OCaml

Hi,

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.

Regards,
Markus

-- 
Markus Mottl          http://www.oefai.at/~markus          markus@oefai.at

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


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

* Re: [Caml-list] Finalizers and threads
  2003-12-12 15:58 [Caml-list] Finalizers and threads Markus Mottl
@ 2003-12-16 23:05 ` Damien Doligez
  0 siblings, 0 replies; 2+ messages in thread
From: Damien Doligez @ 2003-12-16 23:05 UTC (permalink / raw)
  To: OCaml

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


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

end of thread, other threads:[~2003-12-16 23:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-12 15:58 [Caml-list] Finalizers and threads Markus Mottl
2003-12-16 23: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).