This is important when you operate upon your objects
from within idle handlers, but may have freed the object
before the dispatch of your idle handler.
This will fail in a multi-threaded application if the
widget is destroyed before the idle handler fires due
to the use after free in the callback. A solution, to
this particular problem, is to check to if the source
has already been destroy within the callback.
static gboolean
idle_callback (gpointer data)
{
SomeWidget *self = data;
GDK_THREADS_ENTER ();
if (!g_source_is_destroyed (g_main_current_source ()))
{
// do stuff with self
}
GDK_THREADS_LEAVE ();
return FALSE;
}
Calls to this function from a thread other than the one acquired by the
glib.MainContext the glib.Source is attached to are typically redundant, as the
source could be destroyed immediately after this function returns. However,
once a source is destroyed it cannot be un-destroyed, so this function can be
used for opportunistic checks from any thread.
Returns whether source has been destroyed.
This is important when you operate upon your objects from within idle handlers, but may have freed the object before the dispatch of your idle handler.
This will fail in a multi-threaded application if the widget is destroyed before the idle handler fires due to the use after free in the callback. A solution, to this particular problem, is to check to if the source has already been destroy within the callback.
Calls to this function from a thread other than the one acquired by the glib.MainContext the glib.Source is attached to are typically redundant, as the source could be destroyed immediately after this function returns. However, once a source is destroyed it cannot be un-destroyed, so this function can be used for opportunistic checks from any thread.