[GUI] GUIs and events (was: Re: Concurrency)

Wolfgang Thaller wolfgang.thaller@gmx.net
Fri, 14 Mar 2003 00:09:55 +0100


Glynn Clements wrote:

> But non-thread-safe toolkits still exist. X itself isn't necessarily
> thread-safe (thread-safety is optional; AFAIK, XFree86 is thread-safe,
> but some other implementations aren't), and toolkits built atop X tend
> to be thread-safe only if the underlying X libraries are.

... but I know of no reason why a thread-safe toolkit couldn't be based 
on a non-threadsafe one.

> 1. You need to run a specific sequence of toolkit operations without
> any other operations being interleaved.

Yes.

> Even if the toolkit is
> thread-safe, the application itself will still have critical sections
> with regard to its use of the toolkit.

Granted. I don't mean that the CGA should do the user's work - it 
should just do the synchronization that falls within it's scope.

> And if the application has to do its own locking some of the time, it
> may be better to just shift the general problem onto the application.

The main reason why I don't like that is the fact that some toolkits 
are half-threadsafe and require some operations to be done from certain 
OS threads. Other toolkits already are threadsafe and require hardly 
any synchronization on the user's part.
Writing a CGA backend with proper synchronization can be done IMO, but 
writing an application that caters to the different synchronization 
needs of different backends is hard (You'd need to read the docs for 
GTK, Win32, Carbon/Cocoa, etc. in order to do it properly).

> That avoids substantially complicating the toolkit code for a case
> which is seldom used (most GUI programs only call the toolkit from one
> thread).

There seems to be some interest in using Concurrent Haskell for writing 
GUIs. I fear it will be next to impossible to use Concurrent Haskell in 
the GUI part of an application if CGA does not automatically do the 
necessary locking.
If people don't have a problem with saying that all CGA calls should 
come from one (Haskell) thread, then I have no problem with not making 
the first version of CGA threadsafe. For version 2, we'll know better 
a) wether we really need it and b) how much work it will be.

Cheers,

Wolfgang