Removing widgets in the main loop from another thread



Hi all,

i'm trying to add/remove widgets dynamically to a gtk::window from a separate thread. The classes i'm creating hold a singleton to the object that runs the main loop in the separate thread, and i communicate with the main loop thread using the Glib::Dispatcher class.

The widgets will be created in the constructor of my classes, and removed from the window in the destructor. But with the destructor i'm having a slight problem, as the function that actually calls the removeWidget method on the main loop is called asynchroniosly by the dispatcher, therefore, the objects which should get removed will eventually be already destroyed when the main loop receives the
signal.

here's some code how i'm implementing it right now:

remove_dispatcher().connect(sigc::mem_fun(*this, &myObject::myRemoveFunction));

...

void myObject::myRemoveFunction() { // <-- might be called by the dispatcher when the object doesn't exist anymore

 mainProxy->removeWidget(this);

}

myObject::~myObject() {
 remove_dispatcher();  <-- calls myRemoveFunction()
}


My question now is, is there any way to make a glib::dispatcher wait until it actually has emitted the signal until it returns ? This way i could ensure the object still exists when the main loop is called.


thanks !


-robert





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