Date: Mon, 24 Oct 2005 09:42:07 +0900 (JST) Message-Id: <20051024.094207.125901964.garrigue at math.nagoya-u.ac.jp> To: schneck at gmail.com Cc: lablgtk at math.nagoya-u.ac.jp Subject: Re: Threading issues, and custom tree models From: Jacques Garrigue In-Reply-To: References: Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: Robert Schneck-McConnell > I still get occasional weird behavior which seems to be related to > threading issues. I use basically > Thread.create (GtkThread.main ()) I suppose this is a typo, as this wouldn't type correctly anyway. It should be Thread.create GtkThread.main () or (preferably) GtkThread.start () > I observe the following happen: > > (1) The GTK thread is refreshing the display and calling the custom > model's get_value function to get the values in the columns of row r. > (2) Halfway through the columns, the main thread deletes (an ancestor > of) r, emits the GTK signal row_deleted, and moves on. > (3) The GTK thread continues getting the values of the columns of r, > which no longer exists. > > It seems to me that I need to make all changes to the tree model's > data structure wait for GTK. It almost looks like there are functions > in GtkThread to do this, but I don't quite understand. Can anyone > explain? The two functions GtkThread.sync and GtkThread.async are precisely for this purpose. The simplest one is GtkThread.async: it puts an action in a queue, to be executed by the Gtk thread when it has finished with its current work. The other one, GtkThread.sync, is designed for cases where you need an answer from your action. That is, it does the same thing, but keeps the calling thread waiting until the Gtk thread processes the action. Note that you must be more careful with GtkThread.sync: in the case it was called inside a GTK callback, it executes the action immediately (to avoid a deadlock), and this might break some of your invariants. Jacques