[glib] gmain: Close race condition in _g_main_wake_up_all_contexts()
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gmain: Close race condition in _g_main_wake_up_all_contexts()
- Date: Tue, 14 Jun 2011 23:26:19 +0000 (UTC)
commit c9f883f133bc83942484cb8a1349b58ada46b4bc
Author: Colin Walters <walters verbum org>
Date: Tue Jun 14 18:46:06 2011 -0400
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.
glib/gmain.c | 17 +++++------------
1 files changed, 5 insertions(+), 12 deletions(-)
---
diff --git a/glib/gmain.c b/glib/gmain.c
index c84d7b9..47b26cc 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -3774,16 +3774,11 @@ _g_main_wake_up_all_contexts (void)
G_LOCK (main_context_list);
for (list = main_context_list; list; list = list->next)
{
- GMainContext *context;
-
- context = list->data;
- if (g_atomic_int_get (&context->ref_count) > 0)
- /* Due to racing conditions we can find ref_count == 0, in
- * 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);
+ GMainContext *context = list->data;
+
+ LOCK_CONTEXT (context);
+ g_main_context_wakeup_unlocked (context);
+ UNLOCK_CONTEXT (context);
}
G_UNLOCK (main_context_list);
}
@@ -4635,8 +4630,6 @@ unix_signal_helper_thread (gpointer data)
deliver_unix_signal (SIGINT);
if (sighup_received)
deliver_unix_signal (SIGHUP);
- if (sigchld_received)
- deliver_sigchld ();
_g_main_wake_up_all_contexts ();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]