Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
three different labltk behaviors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-08-05 (10:28)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] three different labltk behaviors
From: Jeff Shaw <>

> Ocaml community,
> For fun I wrote a version of Life for ocaml +labltk.
> 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 "":
> works
> 3. Run the toplevel with "" 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 with

  open Tkthread

  let tkth = start ()
  let () = Thread.delay 0.001

and at the end of

  let () = Thread.join tkth

With this it works at least under unix.
Hope it helps.

Jacques Garrigue