RE: Multi-thread problem
- From: "Vallone, Anthony" <anthony vallone lmco com>
- To: Chris Moller <moller mollerware com>, gtk-list gnome org
- Subject: RE: Multi-thread problem
- Date: Tue, 23 Sep 2008 18:30:14 -0400
gdk_threads_enter/leave doesn't work in all cases. Use g_idle_add in
your worker thread to add a callback for your gtk main thread.
From: gtk-list-bounces gnome org [mailto:gtk-list-bounces gnome org] On
Behalf Of Chris Moller
Sent: Tuesday, September 23, 2008 4:52 PM
To: gtk-list gnome org
Subject: Multi-thread problem
Sorry, kind of a long question...
I'm writing a GTK wrapper around a utility that accepts input on its
stdin and dumps results to its stdout, but there's no guarantee that it
will be a strict stimulus/response (or filter-like) behaviour--the
utility can dump to its stdout asynchronously with respect to any
activity on its stdin.
Accordingly, my GTK wrapper uses two threads, one that responds to user
interaction to pipe things to the utility, another that loops on a
blocking read of a pipe from the utility. The output from the utility
is (mostly) dumped into a text buffer (via
gtk_text_buffer_insert_at_cursor()), the text view of which is wrapped
in a scrolled window using gtk_container_add().
The problem is that if I dump enough lines into the text buffer that the
last line is off screen, there doesn't seem to be any way in a
multithreaded environment to automatically force a scroll to get the
last line on-screen. A simple gtk_text_view_place_cursor_onscreen()
doesn't work, nor more complicated sequences like
g_main_context_iteration() doesn't do anything. I even tried a
complicated thing of setting up a pipe between the listener thread and
the main thread, creating a GIO channel, watching that channel, tickling
it from the listening thread, thereby, I hoped, giving the text buffer,
the text view, and the scrolled window a chance to communicate before
doing gtk_text_view_place_cursor_onscreen() from the main thread. That
didn't work either. The vertical GtkAdjustment for the enclosing
scrolled window remains unchanged even after dumping a lot of lines into
the text buffer, no matter which of the above stuff I do.
One of the things the main thread does is accept keystrokes into the
same text buffer used by the listener thread. After inserting a lot of
lines, any keystroke /does/ cause an onscreen scroll.
All the listener thread interaction with the text buffer and the text
view is enclosed in gdk_threads_enter()/gdk_threads_leave().
The FAQ stuff concerning threads (gdk_flush()/XFlush()) didn't help.
Is there anything else I could try?
gtk-list mailing list
gtk-list gnome org
] [Thread Prev