Re: threads gdk/Xlib
- From: Stéphane Konstantaropoulos <stephane cs york ac uk>
- To: Olexiy Avramchenko <olexiy ctech cn ua>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: threads gdk/Xlib
- Date: Mon, 11 Apr 2005 14:16:50 +0100
Le lundi 11 avril 2005 Ã 15:54 +0300, Olexiy Avramchenko a Ãcrit :
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 ?
As I said, I use the Xine library, that creates lots of threads amongst
which some that use Xlib calls (not Gtk+ calls). These are launched only
inside the gtk main loop.
So Gdk calls to Xlib must be done within a XLockedDisplay/XUnlockDisplay
pair.If I call XInitThreads() AFTER gdk_threads_init() it does not work
(Xlib async...).
This is Xorg 6.8 on Linux 2.6.7 with Gtk+ 2.6
--
StÃphane Konstantaropoulos
- Research Student, Computer Science
-- University of York, http://www-users.cs.york.ac.uk/~stephane
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]