Re: [gtkmm] Dispatcher/ Threading



Glenn Pierce wrote:

I have read the doxygen docs and the dispatcher example but I couldn't
find an overview of the threading problem and when / why dispatcher
needs to be used.


Did you also check the FAQ? There's a (rather brief) article about threads there (http://www.gtkmm.org/docs/gtkmm-2.4/docs/FAQ/html/index.html#id2502297).

Gtkmm isn't thread safe, which means that if you manipulate gtkmm objects from several threads at the same time your application will crash and burn. This is not unique to GTK+/gtkmm - pretty much all GUI toolkits have the same characteristics.

To use threads in a GTK+/gtkmm application you have two choices.

1) Do your own locking using gdk_threads_enter() and gdk_threads_leave() to make sure that only one thread can manipulate the GUI at the same time.

2) Only make GTK+/gtkmm calls from one thread. If another thread wants to update the GUI it'll need to ask the "GUI"-thread to do it, which is what you'd use a Glib::Dispatcher for.

IMHO, choice 2 is the preferred choice.

--
Christer Palm



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