<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/12/88bc90aa6873274d55aa4e3daf5c5256"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2003-12-16T23:04:27"
  subject="Re: [Caml-list] Finalizers and threads"
  prev="2003/12/17a764809903dd9118a09590699d8f47"
  next="2003/12/5d2b8084aba6efbe7ecad855a7b3fddc"
  prev-in-thread="2003/12/dfcdf05bb7a89d0d1442fbf3242c80f8"
  prev-thread="2003/12/20d5169ecc59f7b51b1b94bb922a9a69"
  next-thread="2003/12/d1e1de7970b7af2882a64e70200b90ab"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Finalizers and threads">
<msg 
  url="2003/12/dfcdf05bb7a89d0d1442fbf3242c80f8"
  from="Markus Mottl &lt;markus@o...&gt;"
  author="Markus Mottl"
  date="2003-12-12T15:58:14"
  subject="[Caml-list] Finalizers and threads">
<msg 
  url="2003/12/88bc90aa6873274d55aa4e3daf5c5256"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2003-12-16T23:04:27"
  subject="Re: [Caml-list] Finalizers and threads">
</msg>
</msg>
</thread>

<contents>
On Friday, December 12, 2003, at 04:58 PM, Markus Mottl wrote:

&gt; I'd like to know whether it is safe to use "enter_blocking_section"
&gt; in finalization functions (C) to allow execution of other threads when
&gt; some operation there (e.g. shutting down some TCP/IP-connection) may
&gt; 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

</contents>

</message>

