[GUI] Another call for votes

Axel Simon A.Simon at ukc.ac.uk
Tue Mar 18 12:56:37 EST 2003


Cross-posting this to FFI at haskell.org.

On Mon, Mar 17, 2003 at 10:45:07PM +0100, Wolfgang Thaller wrote:
> 	4c) CGA functions may be called from everywhere, at any time. 
> 	Calling CGA functions should not block other concurrent Haskell threads 
> (except if the function is guaranteed to finish in a short time).
> 
> 	4d) First wait and see if 4c is implementable; if not, fall back to 
> 	4b.
 I vote for 4c but I have a question which probably belongs to the FFI 
list. Maybe I am just not understanding the intentions of the FFI but I 
believe that I cannot make Gtk calls threadsafe from within Haskell. Gtk's 
thread issues are shortly explained at:

http://developer.gnome.org/doc/API/2.0/gdk/gdk-Threads.html

The issue seems to be that every call to Gtk has to be surrounded by a 
call to gdk_threads_enter and gdk_threads_leave. How am I supposed to bind 
these functions if I don't have any control about which thread executes a 
call? Suppose

a) I do
foreign import ccall unsafe "gdk_threads_enter" enter :: IO ()
foreign import ccall threadsafe "gtk_function" function :: IO ()
foreign import ccall unsafe "gdk_threads_leave" leave :: IO ()

and execute "enter >> function >> leave" is giving me unique access to the 
Gtk toolkit if every Gtk function call is surrounded by the "enter" and 
"leave" statements. Disadvantage: calling "enter" will block the whole 
Haskell system if there is another (OS) thread executing in Gtk.

b) I change
foreign import ccall unsafe "gdk_threads_enter" enter :: IO ()

to

foreign import ccall threadsafe "gdk_threads_enter" enter :: IO ()

and loose safety: All "enter" calls hijack an OS thread and wait for the 
lock to be available. Meanwhile in Haskell, the Gtk function is called. 

It seems that it is necessary to state that these three functions all 
execute in the same thread. I don't want to write C wrappers for all Gtk 
functions!

I hope I am missing something here.

Axel.




More information about the FFI mailing list