From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 970A3BC69 for ; Tue, 10 Apr 2007 05:56:49 +0200 (CEST) Received: from sys29.mail.msu.edu (sys29.mail.msu.edu [35.9.75.129]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l3A3umq5023602 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 10 Apr 2007 05:56:49 +0200 Received: from shawjef3 by sys29.mail.msu.edu with local (Exim 4.52 #1) id 1Hb7TL-0003FH-Ab; Mon, 09 Apr 2007 23:56:47 -0400 References: <20070410.100759.08076654.garrigue@math.nagoya-u.ac.jp> In-Reply-To: <20070410.100759.08076654.garrigue@math.nagoya-u.ac.jp> From: "Jeffrey Loren Shaw" To: Jacques Garrigue Cc: caml-list@inria.fr Subject: Re: [Caml-list] crash under macos x but not win32 Date: Mon, 09 Apr 2007 23:56:47 -0400 Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: X-Virus: None found by Clam AV X-Miltered: at discorde with ID 461B0B00.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; macos:01 threads:01 async:01 opentk:01 mainloop:01 queued:98 rec:01 caml-list:01 int:01 callback:02 match:02 string:02 garrigue:03 mutex:03 mutex:03 Jacques Garrigue, Thanks for your reply! Inspired by your use of Timer.set in Tkthreads, I decided to use a library I keep handy for queued communication between threads. Using it frees me of having to type sync, async, etc a lot. The only major improvement now would be to make it so that you don't have to poll the queue. I don't know how to do that right now. type 'a qm = {q : 'a Queue.t; m : Mutex.t; c : Condition.t; } let createqm () = {q = Queue.create (); m = Mutex.create (); c = Condition.create (); } let addtoq qm a = Mutex.lock qm.m; Queue.push a qm.q; Condition.signal qm.c; Mutex.unlock qm.m let getfromq_noblock qm = if Mutex.try_lock qm.m then if Queue.is_empty qm.q then ( Mutex.unlock qm.m; None ) else let r = Some (Queue.pop qm.q) in Mutex.unlock qm.m; r else None let testthree () = let top = openTk () in let l = Label.create top in let lconfig s () = Label.configure ~text:s l in let qm = createqm () in let loopfun () = ignore ( Thread.create (fun () -> for i=0 to 5 do Thread.delay 1.; addtoq qm (lconfig (string_of_int i)) done ) () ) in let b = Button.create ~text:"Run the test" ~command:loopfun top in let rec watcher () = Timer.set ~ms:10 ~callback: (fun () -> match getfromq_noblock qm with None -> watcher () | Some f -> f (); watcher () ) in watcher (); pack [l]; pack [b]; mainLoop (); exit 0;; testthree ()