Re: threads & OCamlTK

From: William Chesters (williamc@dai.ed.ac.uk)
Date: Tue Mar 16 1999 - 18:32:29 MET


Date: Tue, 16 Mar 1999 17:32:29 GMT
Message-Id: <13362.199903161732@hobby>
From: William Chesters <williamc@dai.ed.ac.uk>
To: caml-list@inria.fr
Subject: Re: threads & OCamlTK

> And, on a vaguely related topic, is it possible to use threads with
> programs that also use OCamlTK? I know Tk is not threadsafe, but if
> only one thread is calling Tk functions, then perhaps it's still OK?

   No, `Tk.mainLoop' blocks the whole process.

   To get around this, I have a little module that forks and uses
marshalling to communicate GUI code you want executed to the child
process which is running `Tk.mainLoop'. This can be done in a
type-safe way:

        let tkDo =
          TkServer.fork (fun topLevel ->
            Canvas.create topLevel 0 0 400 400, ref [])
        in
        ...
        tkDo (fun canvas, representation ->
          Canvas.delete !representation;
          representation := Canvas.create_text canvas ...)

It is not too inconvenient as long as you don't worry too much about
efficiency (I think my program ends up sending rather big marshalled
closures across the IPC).



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:21 MET