Re: threads gdk/Xlib



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().
You need to put gtk_main() between gdk_threads_enter/leave() if you start any thread before. If you start thread from main loop somehow, these calls aren't necessary.

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.
If you dont use threads in your application you can drop g_thread_init(), gdk_threads_init() calls on the floor. The magic in your case is in XInitThreads() somehow.

Question then:

- Does Gdk call XLockdisplay() at all?
No. gdk_threads_init/enter/leave() stuff acts like XInitThreads(),XLockDisplay(),XUnlockDisplay().

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

- Why is this (ie the interaction between Xlib threads and Gdk threads) not documented anywhere?
What system are you using ? What kind of application do you have ? What version of GTK+ ? Maybe you're linking to some library that wants X threads be initialized ?

        Olexiy




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