Re: threads gdk/Xlib



On Mon, 2005-04-11 at 13:06 +0100, StÃphane Konstantaropoulos wrote:
Hello all,

I am programming a testing app for a gtk widget that embeds Xine and I
am facing little problems with threads and XLib: the application crashes
all the time whith "Xlib: unexpected async reply"

It got fixed only when I called the following functions in the following
sequence:

XInitThreads ();
g_thread_init(NULL);  
gdk_threads_init();
gtk_init(&argc, &argv);

There is no need to put gtk_main() between gdk_threads_enter() and gdk_threads_leave().

If you use a debugging threads library, you'll then see warnings about
"unlocking an unlocked mutex" or similar. If you call gdk_threads_init
(), then all calls to GDK must be within the GDK lock. On the other
hand, there is no reason to call gdk_threads_init() if you are using
GDK from only one thread.

To sum up: there are calls to Xlib from other threads, created by Xine. Gdk also calls Xlib but only from 
the
main thread (my app does not create any). Xine always calls XLockDisplay() before doing any of these calls.

Question then:

- Does Gdk call XLockdisplay() at all?

When necessary, yes. You only need to call XLockDisplay() if you are
doing incredibly grotty low-level Xlib programming. GDK does some of
that, it's conceivable that Xine does too, though I rather doubt it.

- Do you need to call XInitThreads() before gdk_threads_init() ? -> that's the way it seems to work for me.

No, I don't think so. You *do* need to call XInitThreads before making
any other GDK/GTK+ calls (like gtk_init() 
since they might call Xlib functions)

- Why is this (ie the interaction between Xlib threads and Gdk threads) not documented anywhere?

Because there really is no interaction.

Regards,
                                                                Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]