在一个glib main_loop线程中,如果给glib设置了多个watch,则glib回调最终会进入g_main_dispatch方法中,该方法遍历pending_dispatches中的source来执行对应的回调函数,但是我们在使用过程中,有可能会有多个source的情况,比如加了定时器或者多个IO监听,如果在回调前面的source挂的回调函数时,销毁了本次for循环dispatch中后面的source中的回调,则在执行 if (!SOURCE_DESTROYED (source))判断时会失败,导致无法调用本次已经就绪的事件的回调函数。
g_main_dispatch (GMainContext *context)
{
GMainDispatch *current = get_dispatch ();
guint i;
for (i = 0; i < context->pending_dispatches->len; i++)
{
GSource *source = context->pending_dispatches->pdata[i];
context->pending_dispatches->pdata[i] = NULL;
g_assert (source);
source->flags &= ~G_SOURCE_READY;
if (!SOURCE_DESTROYED (source))/判断source是否有效
{
gboolean was_in_call;
gpointer user_data = NULL;