From: Duncan C. <dun...@wo...> - 2005-07-29 12:05:35
|
On Mon, 2005-07-25 at 18:15 -0700, Evan Martin wrote: > On 7/24/05, Duncan Coutts <dun...@wo...> wrote: > > I was asking people on IRC for some feedback on an article I just added > > on writing multi-threaded GUIs with Gtk2Hs: > > http://haskell.org/gtk2hs/archives/2005/07/24/writing-multi-threaded-guis/ > > When I first started learning about Haskell's IO system the GTK > threading requirement is one of the first things I thought of. On > Windows, as I recall, it's not only that GTK isn't thread safe but > it's also that fundamentally the way the Windows event loop works and > how GTK uses it that you just can't do GUI operations from external > threads. (At least, this is my vague memory -- please don't quote me > on it. :P) Yes, I've seen discussions that while multi-threaded programming on X11 is tricky because of the gdk_threads_enter()/gdk_threads_leave() locking requirements, than it becomes nigh on impossible on Win32 because of the nature of the Win32 message passing system. Of course this only applies to multiple OS threads so I still hold out hope for multi-threaded GUIs using Haskell's lightweight threads. > Without thinking about it too hard at least, you could imagine having > all GTK operations that are performed in callbacks just feed their IO > actions into a queue that the "main" thread executes. I thenk that we have to look at that closely to avoid potential deadlocks. The main loop is blocked until the callback returns and if the callback is posting IO actions to the main loop which it needs to be processed to generate a return value for the callback... Now it is possible to recursively invoke the main loop again but it'd need careful thought. > I guess now that I write that you'd want to give them a different > type, like GtkIO, and then it'd complicate the types of functions... > I haven't really thought it fully through, nor do I understand how > Haskell IO "really" works, so it won't hurt my feelings if you tell me > this is a stupid idea. :) I'm still pinning my hopes on getting Haskell lightweight threads that want to access the GUI to run in the same OS thread as GTK by setting up some cooperation between the GTK event loop and GHC scheduler. But I need to try Simon's other suggestions first. BTW, welcome to the mailing list :-) If you need any info from Axel or myself, just ask. Duncan |