From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id E9E74BB81 for ; Fri, 2 Dec 2005 00:20:51 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jB1NKpRl010231 for ; Fri, 2 Dec 2005 00:20:51 +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 AAA15286 for ; Fri, 2 Dec 2005 00:20:50 +0100 (MET) Received: from web34612.mail.mud.yahoo.com (web34612.mail.mud.yahoo.com [209.191.68.146]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id jB1NKnqj013651 for ; Fri, 2 Dec 2005 00:20:50 +0100 Received: (qmail 35923 invoked by uid 60001); 1 Dec 2005 23:20:49 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=fAyJZ7QacwJe0ULTgVtfYz6B0/jaaDIL6Cehu93IUcab/uj4DhBXf1nMUyfFAsUHMJOSk55TOmeWxyXGmnl00xsld83MtR2Qf+NFF0ChUhyzsKLLnJJRCOhl2aALNXoJv0IIRGtX/7vdoN4q2D2u7/GSgdcgGhGNvw0eyi0c5R4= ; Message-ID: <20051201232049.35921.qmail@web34612.mail.mud.yahoo.com> Received: from [69.110.33.39] by web34612.mail.mud.yahoo.com via HTTP; Thu, 01 Dec 2005 15:20:49 PST Date: Thu, 1 Dec 2005 15:20:49 -0800 (PST) From: Ker Lutyn Subject: Re: [Caml-list] More info on the Event module To: Jonathan Roewen , caml-list@inria.fr In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 438F8553.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 438F8551.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 threads:01 threads:01 inverting:01 ocamlopt:01 cmxa:01 cmxa:01 rec:01 printf:01 printf:01 stdout:01 rec:01 haskell:01 ocaml:01 haskell:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.2 required=5.0 tests=FORGED_YAHOO_RCVD autolearn=disabled version=3.0.3 My question about the Event module: the "natural" way to use it appears to be with tons of threads, as in my example below. But using wrap and wrap_abort, etc, it would be possible to promote all events up to a single manager that maintains a list of events and does repeated selects. This would save on threads. Has anyone tried this approach? Is it worth trying? Here's a simple example of using the Event module. It prints an integer every 0.1 seconds, inverting it every 0.3 seconds. $ ocamlopt -o test -I +threads unix.cmxa threads.cmxa test.ml test.ml: open Event let (++) x f = f x let timer seconds o = let run () = while true do Thread.delay seconds; sync (send o ()) done in Thread.create run () let ints x i o = let run () = let rec loop x = sync (receive i); sync (send o x); loop (x + 1) in loop x in Thread.create run () let printer n i = let run () = for x = 1 to n do Printf.printf "%d\n" (sync (receive i)); flush stdout done in Thread.create run () let switch t i o = let run () = let rec loop invert = select [ wrap (receive t) (fun () -> loop (not invert)); wrap (receive i) (fun x -> sync (send o (if invert then (- x) else x)); loop invert) ] in loop false in Thread.create run () let _ = let a = Event.new_channel () in let b = Event.new_channel () in let c = Event.new_channel () in let d = Event.new_channel () in timer 0.1 a ++ ignore; ints 0 a b ++ ignore; timer 0.3 c ++ ignore; switch c b d ++ ignore; printer 10 d ++ Thread.join --- Jonathan Roewen wrote: > Hi, > > I'm looking for some more info on the Event module. I can't figure it out =/ > > Event.sync (Event.send chan 6; Event.receive chan);; blocks forever... > > What I want to do is rewrite some concurrent Haskell code in OCaml > (concurrent haskell code uses GHC/pre-emptive threading). I'm not sure > if the Event module is the way to go. Figuring out how to do the > equivalent of Haskell's channels and mvars is proving difficult =/ > > Jonathan > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > __________________________________________ Yahoo! DSL – Something to write home about. Just $16.99/mo. or less. dsl.yahoo.com