From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA15839; Wed, 17 Dec 2003 00:04:27 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA15828 for ; Wed, 17 Dec 2003 00:04:26 +0100 (MET) Received: from inria.fr (planar.net0.nerim.net [213.41.168.102]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hBGN4PX12014 for ; Wed, 17 Dec 2003 00:04:25 +0100 (MET) Date: Wed, 17 Dec 2003 00:05:19 +0100 Subject: Re: [Caml-list] Finalizers and threads Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v553) From: Damien Doligez To: OCaml Content-Transfer-Encoding: 7bit In-Reply-To: <20031212155808.GB23087@fichte.ai.univie.ac.at> Message-Id: <519CE544-301C-11D8-9FCB-00039310CAE8@inria.fr> X-Mailer: Apple Mail (2.553) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 finalizers:01 threads:01 damien:01 damien:01 finalization:01 threads:01 finalization:01 blocking:01 blocking:01 doligez:01 doligez:01 mottl:02 pushing:02 thread:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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