[Haskell-cafe] what GUI library should i select?

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Mon Nov 13 14:19:16 EST 2006

On Mon, 2006-11-13 at 17:10 +0300, Bulat Ziganshin wrote:

> >> > The one thing you should be aware of is that Windows + Threading +
> >> > Gtk2Hs + Gtk + GHC = Pain.
> >>
> >> why? are you tried to call Gtk2Hs from only one thread?
> > I think so, yes. Or there are bizare -threaded restrictions. Only
> > Duncan (and perhaps Simon Marlow) understand this. I merely got bit by
> > it...
> it will be great to see comments about this. it's impossible to write
> my program without using threaded RTS

This is a problem for all GUI libs, it's not something that's different
between Gtk2Hs and wxHaskell. I think the problem is better understood
in Gtk2Hs because we have tried to tackle it.

I've written some multi-threaded GUI apps when using the single-threaded
RTS. I have no idea if you can use threads with wxHaskell, you'd have to
ask someone who knows more about it.

As for the threaded RTS, currently that's only ok if you never make GUI
calls from more than one Haskell thread. The reason for the restriction
is that GUI libs like wxWiddgets and Gtk+ are really designed to be used
in a single threaded manner[1]. I know Gtk+ does have some support for
using multiple threads but it requires a lot of explicit locking so it's
not easy to use from Haskell where we expect to be able to use light
weight threads with ease.

The problem at the moment with GUIs and GHC's threaded RTS is that there
is now way to specify that all the Haskell threads that want to do GUI
stuff must run on a single OS thread. It's not impossible to solve but
it requires either more support from the RTS or it needs a totally
different approach, perhaps using a Haskell-level threading GUI monad
rather than the IO monad.


[1] in fact on windows it's even worse, not only must there be no
concurrent modification of GUI objects but the windows GDI enforces that
*only* the thread that created an object may access/modify that object.
That's a pretty severe restriction which is why we would normally say
that the GUI is just single threaded rather than going into the nasty
details of how exactly you really do GUIs with multiple OS threads. It's
so hard to do that it's effectively just single threaded.

More information about the Haskell-Cafe mailing list