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 4E4E4BB91 for ; Mon, 24 Jan 2005 21:00:40 +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 j0OK0duC022964 for ; Mon, 24 Jan 2005 21:00:39 +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 VAA20454 for ; Mon, 24 Jan 2005 21:00:38 +0100 (MET) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.207]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0OK0cc5022961 for ; Mon, 24 Jan 2005 21:00:38 +0100 Received: by rproxy.gmail.com with SMTP id f1so58945rne for ; Mon, 24 Jan 2005 12:00:37 -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:in-reply-to:user-agent; b=frE1TL2Tq+eQEGK43LUZWphbrTpMpqkX9+ij639Ie+JWumOn1fZiG0X/eYriNFFaHGSQnGTzO//W7J/T4i2ScXqIryFuDGCtvM1Hj0pKUar4OWkdBYTqO71jhCWqUfBp0juSKjSq+uJqv0vA18/hlBdxs66rVsWGukm6QubzTBI= Received: by 10.38.158.11 with SMTP id g11mr99302rne; Mon, 24 Jan 2005 12:00:37 -0800 (PST) Received: from localhost ([141.155.88.179]) by smtp.gmail.com with ESMTP id 58sm942rnc.2005.01.24.12.00.36; Mon, 24 Jan 2005 12:00:37 -0800 (PST) Date: Mon, 24 Jan 2005 15:00:35 -0500 From: Markus Mottl To: Vincenzo Ciancia , SooHyoung Oh , Alex Baretta , Olivier Andrieu Cc: OCaml Subject: Re: C-threads & callbacks Message-ID: <20050124200035.GA12714@quant3.janestcapital.quant> Mail-Followup-To: Vincenzo Ciancia , SooHyoung Oh , Alex Baretta , Olivier Andrieu , OCaml References: <20050120182313.GB4919@quant3.janestcapital.quant> <41F00881.60406@barettadeit.com> <20050120201936.GA18266@quant3.janestcapital.quant> <20050121.011925.78707709.oandrieu@nerim.net> <20050120182313.GB4919@quant3.janestcapital.quant> <41F057D2.4020407@compiler.kaist.ac.kr> <41F0A45A.2080806@barettadeit.com> <20050120182313.GB4919@quant3.janestcapital.quant> <41F057D2.4020407@compiler.kaist.ac.kr> <200501211042.31749.vincenzo_mlRE.MOVE@yahoo.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050121.011925.78707709.oandrieu@nerim.net> <41F0A45A.2080806@barettadeit.com> <41F057D2.4020407@compiler.kaist.ac.kr> <200501211042.31749.vincenzo_mlRE.MOVE@yahoo.it> User-Agent: Mutt/1.4.1i X-Miltered: at nez-perce with ID 41F553E7.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41F553E6.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; markus:01 mottl:01 markus:01 mottl:01 wrote:01 ocaml:01 baretta:01 wrote:01 ocaml:01 andrieu:01 marshalling:01 waits:01 converts:01 ocaml-values:01 waits:01 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: Hi, thanks for all the replies. I have just implemented a solution, which seems to be very satisfactory for our purposes. On Fri, 21 Jan 2005, SooHyoung Oh wrote: > I'v resolved the same problem using TCP/IP communication between Ocaml > thread and C thread. This would unfortunately have been way too much overhead. On Fri, 21 Jan 2005, Alex Baretta wrote: > What exactly are you doing, Markus? I'm interested because we, too, here > at DE&IT, use Ocaml for realtime applications. We are logging financial realtime data (trades) with enormously high data volume (tens of thousands of ticks/trades per second at peak times). On Fri, 21 Jan 2005, Olivier Andrieu wrote: > What about using a pipe ? the C callback stuffs its data in the pipe > (perhaps converted to marshalled caml values) and on the other end, > the caml callback is waiting with a blocking read. This would still require marshalling overhead. My solution now looks as follows: I prespawn an OCaml-thread, which immediately goes into C-land. There it waits on a condition variable (within a blocking section to let other OCaml-threads run) until some C-thread makes data available and notifies it. Then the OCaml-thread converts the available data to OCaml-values and performs the callback. In the meanwhile the C-thread blocks on a condition variable until the result is available. Once the OCaml-thread returns, it notifies the C-thread and waits for more data again. The C-thread continues as desired (terminates or does something else, etc.). The only overhead is context switching, everything else is negligible. It would still be nice if there were an easy way to let C-threads safely migrate to OCaml-land without all this thread-coordination... Regards, Markus -- Markus Mottl markus.mottl@gmail.com http://www.ocaml.info