Re: multithreading problem.

>  I am writing a multi-threaded application using GTK. Whenever I try to
>call a gtk function in a thread I get the following X error:
>The program 'a.out' received an X Window System error.
>This probably reflects a bug in the program.


> I believe I have followed the instructions given in the FAQ about
> The thread is being called from a callback function (triggered by a
>button). The thread calls a function called show_up() which displays a
>dialog (this is where I get the Xerror). Every call to a gtk function in
>show_up() is preceeded by threads_enter() and followed by threads_leave().

*every* glib/gdk/gtk/xlib function *everywhere* has to be surrounded by
such calls.

>	I called gthread_init() at the beginning of the program
>and the gtk_main() is surrounded by threads_enter(), threads_leave() calls.
>	It probably doesn't make any difference but I am using pthreads.

no, it makes no difference. there's no big secret to doing this. you
either wrap *every* call, or you use the generally simpler and more
designer-style approach of having only a single thread ever make
glib/gdk/gtk/xlib calls (others communicate with that thread via a
pipe or some other mechanism). it works - i've written several MT
programs that use GTK+ (in some cases, with up to 10 threads), and i
have no problems with any of this stuff until i forget the rule and
end up inadvertently calling a glib/gdk/gtk/xlib function from the
wrong thread.


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