Re: List/TreeStore and threads



Well, if you wanted to go the route of dispatcher, I'll outline how I did it in a past life:

1. "Queue" object which holds "TreeStore items for insertion"
  - insert method, ability for window to get queue and lock it (mutex)

2. MainWindow which holds the TreeView
  - contains dispatcher that is bound to a method that does insertion into the Gtk::TreeStore

On inserting an item into the queue (outside ui thread), have the method emit the dispatcher signal, the dispatcher then will run and dequeue the item, inserting it from the ui thread. This would create the "update as we go" behaviour you're going for, I think....

The dispatcher is more useful than it seems, and I am 95% sure there is no "thread-safe" insert otherwise.

As for swapping a tree store, I think you can do it, just have to invalidate the TreeView after changing it.

Sorry I don't have pseudo-code or particularly exact answers, I am at work and don't have access to a C++ editor/gtk install.

Cheers,

Kevin

P.S. Sorry Yann, didn't mean to hit reply instead of reply-all


On Fri, Aug 2, 2013 at 9:17 AM, Yann Leydier <yann leydier info> wrote:
Thanks Kevin.

I know of the dispatcher but the problem is that I need to fill a TreeStore: the data is very complex and hard to send through a dispatcher.

Does anyone know if filing a store that is not bound to any TreeView would be ok (out of the main thread, I mean)? Is so, I could just swap the TreeView's store with the new one.

Thanks
yann


On 02/08/13 15:10, Kevin Brightwell wrote:
I'm not entirely sure of your problem, but I do know that GTK does not guarantee any thread safety for it's components. You should not be modifying the TreeView outside the UI thread. If this is how GTK manifests this problem, so be it. There is a Glib::Dispatcher() [1] [2] which would allow you to spawn the dispatcher in the UI thread, then push things from a worker thread and make sure the value gets updated on the UI.

I hope I'm actually helping the problem and not just being critical on style. :(

Cheers,

Kevin

[1] https://developer.gnome.org/glibmm/2.35/classGlib_1_1Dispatcher.html
[2] https://developer.gnome.org/gtkmm-tutorial/3.8/sec-using-glib-dispatcher.html.en



On Fri, Aug 2, 2013 at 8:51 AM, Yann Leydier <yann leydier info> wrote:
Hi,

my application fills some TreeStrores and ListStores at runtime but the data is read from large files and the computation of some values takes time. Therefore I put a progress bar in a splash window and fill the store in another thread.

The TreeView fills oddly: once the lines do not fit anymore on the display, the scollbar is not updated. I tried to add gdk_threads_entrer() and gdk_threads_leave() before and after the calls to XXXStore::append() but it did not change anything.

First question: are the stores really thread unsafe? I tend to consider them as non-UI classes, so TreeView should be the one handling the thread-safety…

Second question: how do I make sure I do not mess up with the thread safety when filling my stores?

Thanks a lot,
yann
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list



--
Kevin Brightwell
BESc. and BSc. Candidate 2015
Western University www.westernu.ca
e. kevin brightwell2 gmail com c. 226.678.4927




--
Kevin Brightwell
BESc. and BSc. Candidate 2015
Western University www.westernu.ca
e. kevin brightwell2 gmail com c. 226.678.4927


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