Fw: [gtkmm] threads



Am 14.10.2003 um 00:01 Uhr haben Sie geschrieben:
> (snip)
> 
> So I've got a few questions:
> 
> 1. Currently, the Scene thread is the only thread that'll be
> invoking the Dispatcher, i.e., it's the only sender thread.
> There's only one GtkViewer object and it is single-
> threaded. Do I need to call Glib::thread_init in the
> GtkViewer?

If I remember correctly, it is best to call Glib::thread_init() from
main() after creating your Gtk::Main instance.

> 2. Is it safe for the Scene thread to invoke the
> Glib::Dispatcher via the  GtkViewer::notify method, even
> though that Scene thread doesn't make any
> other Glib calls?

Yes, no problem.

> 3. Assuming that at some point in the future I create
> multiple Scene threads, each of which want to
> send "copy" messages to the single-threaded
> GtkViewer, do I need to put a lock around the Dispatcher
> in the GtkViewer::notify method? From the
> Glib::Dispatcher documentation page, it sounds like not, 
> but it's not clear to me whether that assumes that
> each sender thread has its own instance of a Dispatcher.
> In the scenario I'm describing, there is only one
> Dispatcher object, and it belongs to the
> single GtkViewer object.

You have to use the Glib::Dispatcher instance of the GUI-thread from
the "worker" threads. You needn't do any locking because POSIX write()
(which Glib::Dispatcher uses internally) is atomic for small amounts of
data. (This amount is system dependant and there is a constant
specifying it - I don't have my UNIX Programming book at hand to look
it up, though.)

Regards,

  Martin







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