[gtkmm] multithreaded widget



Hello gtkmm folks--

I'm trying to create my own gtkmm widget that serves as the front-end
for a multithreaded back-end process, in my case a video display
engine.  I couldn't find this documented anywhere, so please forgive
me if this is a FAQ.

My widget inherits from GTK::DrawingArea, and overrides functions like
on_expose_event, on_configure_event, and on_map_event.

In my on_map_event, I use calls from gdk/gdkx.h to get the underlying
X window display and window data structures.  I then spin up my
back-end threads.

All calls to GTK are localized in the main thread, and as a result I
don't call gdk_threads_enter/gdk_threads_leave.  (Should I?  If so, 
where?)  Independently of the main GUI thread, the back-end display 
thread makes calls to X windows, always protected by XLockDisplay and
XUnlockDisplay.

This mostly works, but when the user stresses the windowing system by
continually resizing the window, I get an Xlib: unexpected async reply
message, and then the GUI thread hangs.  A stack backtrace of the GUI
thread at this point looks like this:

#0  0x420d3b2e in select () from /lib/i686/libc.so.6
#1  0x408f1b28 in _XlcPublicMethods () from /usr/X11R6/lib/libX11.so.6
#2  0x40848047 in _XRead () from /usr/X11R6/lib/libX11.so.6
#3  0x40848b67 in _XReply () from /usr/X11R6/lib/libX11.so.6
#4  0x40844075 in XSync () from /usr/X11R6/lib/libX11.so.6
#5  0x4054d5cb in _gdk_x11_copy_to_image () from /usr/lib/libgdk-x11-2.0.so.0
#6  0x40522e09 in _gdk_drawable_copy_to_image ()
   from /usr/lib/libgdk-x11-2.0.so.0
#7  0x4052d3bf in gdk_pixmap_copy_to_image () from /usr/lib/libgdk-x11-2.0.so.0
#8  0x40522e09 in _gdk_drawable_copy_to_image ()
   from /usr/lib/libgdk-x11-2.0.so.0
#9  0x4052b456 in gdk_pixbuf_get_from_drawable ()
   from /usr/lib/libgdk-x11-2.0.so.0
#10 0x4030da6f in gtk_image_expose () from /usr/lib/libgtk-x11-2.0.so.0
#11 0x4017363d in Gtk::Widget_Class::expose_event_callback(_GtkWidget*, _GdkEventExpose*) (self=0x80c2288, p0=0xbfffd970) at widget.cc:3825
...

(In addition to the video display widget, the window also has a
GTK::Toolbar with pixmaps as button images; I am reasonably sure the
program is dying while processing the expose event on those images.)

All the other threads continue running fine, and in particular my
video display thread continues correctly copying data to the window.

If I comment out the X windows calls from the back-end thread, the
problem goes away.

So: what am I missing?

Thanks for your help,

--Howdy


  =============================
  Howdy Pierce
  Managing Partner
  Cardinal Peak, LLC

  email: howdy cardinalpeak com
  work: (303) 665-3962
  cell: (303) 589-1645
  =============================







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