From: Axel S. <A....@uk...> - 2003-02-24 14:45:56
|
On Fri, Feb 21, 2003 at 06:46:59PM +0100, Nick Name wrote: > Hi all, back from my examinations period, I'll have some spare time > (there's gdkPixbuf waiting for me). Good! > As you can guess from the subject, I have troubles with threads, while > making a small experiment with gtk2hs. > > The action mainGUI blocks and makes all the threads block; a current > workaround I am using is (note that Widget is not Gtk.Widget) > > runGUI :: Widget -> IO () > runGUI (Widget w) = do > forkIO (do > Gtk.initGUI > w > sequence_ (repeat (threadDelay 20000 >> > Gtk.mainIterationDo False))) > return () > > However, the interface is not responsive, and I fear that on slow > computers 20 milliseconds could be too few. I think this is the more clumsy version of forcing gtk and ghc run in parallel. Instead of running the main loop of Gtk once in a while I think you are better off running Haskell when Gtk is idle: Gtk.idleAdd (yield >> return False) Gtk.priorityDefault Gtk.mainGUI > Maybe the attribute "threadsafe" should be added somewhere. I don't know > where it could be added, and if gtk2 is thread safe. Gtk itself is not multi-threaded but it is thread safe. That is, the application can use several threads that can all call Gtk, but no two calls of Gtk functions may run at the same time. As long as ghc does not have native OS threads, this is not a problem. > Are you already aware of the problem? What could you advice on the use > of ghc threads and gtk2hs? Either use the idleAdd hack or call "mainIterationDo False" when you do something which takes a little longer. I might not see all the problems, so if this does not solve your problem, let me know. Axel. |