mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-23 15:49:16 +02:00
gmain: Close race condition in _g_main_wake_up_all_contexts()
Running gthread/tests/spawn-multithreaded in a loop, I very easily hit: GLib-CRITICAL **: g_main_context_wakeup: assertion `g_atomic_int_get (&context->ref_count) > 0' failed Testing the refcount still left a window where we would fall into the assertion. Fix this by just locking the context.
This commit is contained in:
parent
211d7adf6e
commit
c9f883f133
15
glib/gmain.c
15
glib/gmain.c
@ -3774,16 +3774,11 @@ _g_main_wake_up_all_contexts (void)
|
|||||||
G_LOCK (main_context_list);
|
G_LOCK (main_context_list);
|
||||||
for (list = main_context_list; list; list = list->next)
|
for (list = main_context_list; list; list = list->next)
|
||||||
{
|
{
|
||||||
GMainContext *context;
|
GMainContext *context = list->data;
|
||||||
|
|
||||||
context = list->data;
|
LOCK_CONTEXT (context);
|
||||||
if (g_atomic_int_get (&context->ref_count) > 0)
|
g_main_context_wakeup_unlocked (context);
|
||||||
/* Due to racing conditions we can find ref_count == 0, in
|
UNLOCK_CONTEXT (context);
|
||||||
* that case, however, the context is still not destroyed
|
|
||||||
* and no poll can be active, otherwise the ref_count
|
|
||||||
* wouldn't be 0
|
|
||||||
*/
|
|
||||||
g_main_context_wakeup (context);
|
|
||||||
}
|
}
|
||||||
G_UNLOCK (main_context_list);
|
G_UNLOCK (main_context_list);
|
||||||
}
|
}
|
||||||
@ -4635,8 +4630,6 @@ unix_signal_helper_thread (gpointer data)
|
|||||||
deliver_unix_signal (SIGINT);
|
deliver_unix_signal (SIGINT);
|
||||||
if (sighup_received)
|
if (sighup_received)
|
||||||
deliver_unix_signal (SIGHUP);
|
deliver_unix_signal (SIGHUP);
|
||||||
if (sigchld_received)
|
|
||||||
deliver_sigchld ();
|
|
||||||
_g_main_wake_up_all_contexts ();
|
_g_main_wake_up_all_contexts ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user