Re: gtk + threads

Muthu wrote:

Im assuming you are talking about X Errors.
Which cropup on the terminal, and say
X out of sync, etc.

A little bit of reading the gtk-app-devel list
will show you how, X window system calls must be made from only
one thread. Making X calls from two threads
will cause a crash.
actually, that's not true. assuming your X11 client libraries are thread-safe, you've called XInitThreads(), and are either a) using two separate Display* pointers obtained via two different invocations of XOpenDisplay(), or b) locking a single Display* with XLockDisplay() while using it in all threads, you should be fine.

I think you must set the gtk_* calls from the
idle_function alone. Thatis , it must be a
part of the main loop that works the GUI.
or, you have to start off your app with:

g_init(&argc, &argv);

wrap gtk_main() between gdk_threads_enter() and gdk_threads_leave(), and, anytime you access gdk/gtk from a:
1) idle function
2) timeout function
3) function running in a thread other than the main one
you surround such calls with gdk_threads_enter()/gdk_threads_leave().

now, this is sometimes a bit of work, so often it's easier -- as the original poster hinted at -- just to not init the threads system at all, and, when you need to call gtk/gdk from another thread, either stick it in an idle function that gets scheduled via g_idle_add(), or use a GAsyncQueue to communicate between the GUI thread and the worker threads.


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