Re: Threads and gtkmm
- From: Chris Vine <chris cvine freeserve co uk>
- To: Yann Leydier <yann leydier info>
- Cc: gtkmm-list gnome org
- Subject: Re: Threads and gtkmm
- Date: Tue, 29 Mar 2011 12:51:33 +0100
On Tue, 29 Mar 2011 11:42:56 +0200
Yann Leydier <yann leydier info> wrote:
> Thanks for the info. I was still using g_idle_connect with static
> methods to communicate between threads…
I assume you mean g_idle_add(), and that's a perfectly good way to do
it, and is thread safe, but you forfeit trackability. (Although if you
are passing static class member functions to the callback argument of
g_idle_add() you technically have undefined behaviour because static
member functions have C++ linkage specification and not C linkage.
However, it will work OK with gcc, and glibmm does it, so you are not
adding any greater unportability.)
> I have a question on how to transmit the dispatcher to an object. The
> documentation seems to indicate that the default copy constructor and
> operator are used. Does this mean that I can send my dispatcher
> object to other objects directly ?
> MyClass
> {
> public:
> MyClass(const Glib::Dispatcher &d):
> dispatcher(d)
> { }
> private:
> Glib::Dispatcher dispatcher;
> { }
>
> Or shall I use a pointer (or a reference) (that can be dangerous
> depending on the destruction order of the objects) ?
> MyClass
> {
> public:
> MyClass(Glib::Dispatcher *d):
> dispatcher(d)
> { }
> private:
> Glib::Dispatcher *dispatcher;
> }
The first won't work because Dispatchers can't be copied (this is a
feature not a bug). The second is not desirable because passing around
Dispatchers by pointer is likely to leave your code with dangling
pointers.
If a Dispatcher is a class member, why not provide an accessor
function, or make it a public member? These would be the normal ways of
doing it (as with sigc::signal objects).
Chris
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]