Re: pthreads + gtk
- From: Paul Davis <pbd op net>
- To: ecos navosha com
- Cc: gtk-list gnome org
- Subject: Re: pthreads + gtk
- Date: Thu, 19 Sep 2002 09:07:42 -0400
>I am working on a program that gets data from a socket asynchronously. As a
>result, the only way I could figure out to update the display as data came in
>was to use pthreads.
>
>I'm using a clist, and the update isn't immediate, sometimes it takes several
>seconds to see the data update onto the screen. Other times, elements become
>invisible for some time, although the data is there, just not visible.
>
>I figure there is 2 possibilities:
>
>The one I hope it is:
>
>1) I have some experience with X11 coding, and it looks like I need to send
>the GTK equivalent of XSync, but I cannot find it in the documentation.
>
>The one I'm praying it isn't:
>
>2) GTK isn't compatible with pthreads. I know X11 isn't re-entrant. If GTK
>can't handle asynchronous input, how should I handle asynchronous data input?
>
>I *could* cache the data in one thread, and then cause an "event" in the
>gtk_main () loop to cause the data to be processed.. How do I send an event
>from one process to another?
1) read the GTK+ FAQ. of course its compatible with pthreads
2) you have two options when using threads:
a) surround ****EVERY*** call to a GDK, GTK or X11 function
with gdk_threads_{enter,leave} pair
b) have only one thread make calls to GDK, GTK or X11, and
have all other threads send a request to the GUI thread
via a pipe. the pipe is "wired into" the GUI main loop
by using gtk_input_add() or its glib cousins.
3) search the mailing list archives because there are lots and lots
and lots of other messages about this.
I vastly prefer 2.b. I have several large scale multithreaded programs
that use GTK.
--p
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]