From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA16225 for caml-redistribution; Wed, 17 Mar 1999 13:44:07 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA12070 for ; Tue, 16 Mar 1999 18:32:32 +0100 (MET) Received: from postbox.dai.ed.ac.uk (postbox.dai.ed.ac.uk [129.215.41.196]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id SAA05354 for ; Tue, 16 Mar 1999 18:32:30 +0100 (MET) Received: from hobby (hobby.dai.ed.ac.uk [129.215.25.37]) by postbox.dai.ed.ac.uk (8.8.7/8.8.7) with SMTP id RAA07886; Tue, 16 Mar 1999 17:32:29 GMT Date: Tue, 16 Mar 1999 17:32:29 GMT Message-Id: <13362.199903161732@hobby> From: William Chesters To: caml-list@inria.fr Subject: Re: threads & OCamlTK Sender: weis > 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).