Re: multithreading problem.
- From: Paul Davis <pbd op net>
- To: Robert Walker <bob step polymtl ca>
- Cc: gtk-list gnome org
- Subject: Re: multithreading problem.
- Date: Tue, 04 Jun 2002 09:00:46 -0400
>Hi,
> 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.
correct.
> I believe I have followed the instructions given in the FAQ about
>multi-threading.
>
> 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.
--p
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]