On Sat, Dec 15, 2012 at 9:39 PM, José Romildo Malaquias <j.romildo@gmail.com> wrote:
When updating a sorted tree model in a separate thread, most of the time
the application crashes with a critical error:

  (TreeSort:15588): Gtk-CRITICAL **: IA__gtk_tree_model_sort_convert_iter_to_child_iter: assertion `VALID_ITER (sorted_iter, tree_model_sort)' failed
  TreeSort: user error (ListStore.getRow: iter does not refer to a valid entry)

There are two buttons in the application: only one uses a separate
thread. Keep pressing it and soon the application will crash. With the
other button it does not crash.

This is not a bug, it is expected behavior --- Gtk+ itself does not really support multithreading (nor does X11, or at least not Xlib:  there is a thing you can do that will turn on thread safety, but it works by wrapping *every* Xlib call in a mutex to ensure that only one thread is ever inside Xlib, because Xlib's internals are not thread safe).  The Haskell bindings can do nothing substantive about this fundamental lack of proper thread support in Gtk+/Xlib.

With gtk2hs, postGuiAsync can be used in threads to ask the main thread to do something involving X11 or Gtk+.  (Note the Async part; the thread will not pause and wait for a response from the main thread.)  I think a future version of gtk2hs is supposed to automatically do that in threads, but IIRC this will still be async in nature so won't be suitable for some operations.

brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net