From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id A094ABB91 for ; Thu, 20 Jan 2005 20:23:43 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0KJNhAn002155 for ; Thu, 20 Jan 2005 20:23:43 +0100 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 UAA09531 for ; Thu, 20 Jan 2005 20:23:42 +0100 (MET) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.199]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0KJNgp0002151 for ; Thu, 20 Jan 2005 20:23:42 +0100 Received: by rproxy.gmail.com with SMTP id r35so8409rna for ; Thu, 20 Jan 2005 11:23:41 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:date:from:to:cc:subject:message-id:mail-followup-to:references:mime-version:content-type:content-disposition:content-transfer-encoding:in-reply-to:user-agent; b=Y8UnrlV8zXSaZK9Prcfgd/hd9b+blK6WaI1gfKYY2RzSf4GWYDnSsIEj6sSoua2BhlZsl9E9mFj2wKQVY2kFg4LnM8nDbmmntm1U3vFVb7uEN/UO1a8e6w+5e488kgImL1QjwrlzuyaEe+8/5PLB8inJviDdI2WLjmGreoU+AIQ= Received: by 10.38.207.47 with SMTP id e47mr111243rng; Thu, 20 Jan 2005 11:23:41 -0800 (PST) Received: from localhost ([141.155.88.179]) by smtp.gmail.com with ESMTP id 71sm2247rnc.2005.01.20.11.23.40; Thu, 20 Jan 2005 11:23:40 -0800 (PST) Date: Thu, 20 Jan 2005 14:23:38 -0500 From: Markus Mottl To: Daniel =?iso-8859-1?Q?B=FCnzli?= Cc: caml-list caml-list Subject: Re: [Caml-list] C-threads & callbacks Message-ID: <20050120192338.GC4919@quant3.janestcapital.quant> Mail-Followup-To: Daniel =?iso-8859-1?Q?B=FCnzli?= , caml-list caml-list References: <20050120182313.GB4919@quant3.janestcapital.quant> <4D24C0F4-6B15-11D9-9ECD-000393DBC266@epfl.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4D24C0F4-6B15-11D9-9ECD-000393DBC266@epfl.ch> User-Agent: Mutt/1.4.1i X-Miltered: at nez-perce with ID 41F0053F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41F0053E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; markus:01 mottl:01 markus:01 mottl:01 caml-list:01 donnerstag:01 ocaml's:01 myfun:01 val:01 spawned:01 ocaml:01 ocaml:01 runtime:01 segfault:01 ...:98 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.5 required=5.0 tests=INFO_TLD,RCVD_BY_IP autolearn=disabled version=3.0.0 X-Spam-Level: Daniel Bünzli schrieb am Donnerstag, den 20. Jänner 2005: > I don't understand what you are refering to. I don't think there's a > problem as long as you take care to acquire ocaml's global lock to > exectue the callbacks. > > #include > ... > caml_leave_blocking_section(); > callback(*caml_named_value("myfun"), Val_unit); > caml_enter_blocking_section(); > ... > > This ensures that callbacks into caml are properly serialized. This only works if the callback is performed by a thread that was spawned by OCaml (i.e. OCaml -> C -> OCaml). In this case the runtime knows what the "current thread" is. But if a C-thread executes "caml_leave_blocking_section" (C -> OCaml), it can segfault there, because there may be no "current thread". And if there is, it is not the C-thread but another currently executing OCaml-thread, which will mess things up later. That's why there should be some way to register a C-thread with the OCaml-runtime. Currently this does not seem to be possible without hacking the OCaml-implementation. Regards, Markus -- Markus Mottl markus.mottl@gmail.com http://www.ocaml.info