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.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE 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 ACABCBC69 for ; Tue, 10 Apr 2007 03:08:11 +0200 (CEST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l3A18959021716 for ; Tue, 10 Apr 2007 03:08:10 +0200 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id l3A1847Y017599; Tue, 10 Apr 2007 10:08:05 +0900 (JST) Date: Tue, 10 Apr 2007 10:07:59 +0900 (JST) Message-Id: <20070410.100759.08076654.garrigue@math.nagoya-u.ac.jp> To: shawjef3@msu.edu Cc: caml-list@inria.fr Subject: Re: [Caml-list] crash under macos x but not win32 From: Jacques Garrigue In-Reply-To: References: X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 461AE379.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; macos:01 ocaml:01 ocaml:01 mingw:01 opentk:01 mainloop:01 labltk:01 threads:01 threads:01 labltk:01 callable:01 async:01 opentk:01 mainloop:01 async:01 From: "Jeffrey Loren Shaw" > The following works as intended in Win32 (the ui counts slowly from 0 to 5), > but crashes in Mac OS X with "Bus Error". I'm running ocaml 3.09.3 installed > with macports. For windows I used the Ocaml 3.09.3 MinGW binary > distribution. > > (* looptest.ml *) > > open Tk > > let testone () = > let top = openTk () in > let l = Label.create top in > let loopfun () = > ignore > ( > Thread.create > (fun () -> > for i=0 to 5 do > Thread.delay 1.; > Label.configure ~text:(string_of_int i) l > done > ) > () > ) > in > let b = Button.create ~text:"Run the test" ~command:loopfun top in > pack [l]; > pack [b]; > mainLoop ();; > > testone () > > (* end looptest.ml *) > > runs with: ocaml -I +labltk -I +threads unix.cma threads.cma labltk.cma > looptest.ml The Aqua version of Tk is notoriously unstable when used with labltk, but this doesn't seem to be the problem here. Rather, it appears not to be reentrant (or rather not callable from several threads.) By the way I am surprised you have no problem under Win32, which often has reentrance problems too. Anyway, there is a Tkthread module to solve these reentrance problems. Here is the code using it, adding "sync" and "async" where needed. open Tk open Tkthread let tk = start () (* Calls openTk and mainLoop in a new thread *) let testone () = Thread.delay 0.1; (* wait for initialization *) let l = sync Label.create top in let loopfun () = ignore ( Thread.create (fun () -> for i=0 to 5 do Thread.delay 1.; async (Label.configure ~text:(string_of_int i)) l done ) () ) in let b = sync (Button.create ~text:"Run the test" ~command:loopfun) top in async pack [l]; async pack [b]; Thread.join tk;; (* wait for mainLoop to finish *) testone () And start it with ocaml -I +labltk -I +threads unix.cma threads.cma labltk.cma tkthread.cmo looptest2.ml The wait for initialization part is kind of hacky, as the thread start function was rather intended for interactive use, but it should be portable enough. Jacques Garrigue