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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id DB559BC69 for ; Sun, 5 Aug 2007 12:28:37 +0200 (CEST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l75ASZLw017224 for ; Sun, 5 Aug 2007 12:28:37 +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 l75ASYXO016384; Sun, 5 Aug 2007 19:28:34 +0900 (JST) Date: Sun, 05 Aug 2007 19:28:30 +0900 (JST) Message-Id: <20070805.192830.98869896.garrigue@math.nagoya-u.ac.jp> To: shawjef3@msu.edu Cc: caml-list@inria.fr Subject: Re: [Caml-list] three different labltk behaviors From: Jacques Garrigue In-Reply-To: <46B5123A.9020702@msu.edu> References: <46B5123A.9020702@msu.edu> X-Mailer: Mew version 4.2 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 46B5A653.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; labltk:01 ocaml:01 ocaml:01 labltk:01 wikipedia:01 wiki:01 bytecode:01 tkerror:01 toplevel:01 toplevel:01 mingw:01 inserting:01 wrote:01 unix:01 compile:01 From: Jeff Shaw > Ocaml community, > For fun I wrote a version of Life for ocaml +labltk. > > http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life > > Here are the 3 ways I've tried to run it and the results: > > 1. compile to bytecode or native: > "Fatal error: exception Protocol.TkError("Tcl/Tk not initialised")" > > 2. #load all the libraries into the toplevel (or give them as command > line arguments) then #use "lifemain.ml": > works > > 3. Run the toplevel with "lifemain.ml" as an argument: > gives an empty Tk window > > The results are the same on Mac OS X and Windows XP (mingw). There are two problems: 1) There is a buglet in Tkthread, which was originally intended to be used only with the toplevel. Namely, the Tkthread.sync command executes immediately in the current thread if there is no tk thread running. This is to avoid deadlocks, but the new tk thread registers itself, so there is a race condition if sync is called immediately after Thread.start. For the time being, this can be fixed by inserting Thread.delay 0.001 2) You must "join" the tk thread before exiting, otherwise you will exit immediately. So you should correct the beginning of lifemain.ml with open Tkthread let tkth = start () let () = Thread.delay 0.001 and at the end of lifemain.ml let () = Thread.join tkth With this it works at least under unix. Hope it helps. Jacques Garrigue