After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 658182 - g_main_loop_quit() race condition
g_main_loop_quit() race condition
Status: RESOLVED DUPLICATE of bug 632301
Product: glib
Classification: Platform
Component: mainloop
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-09-04 14:44 UTC by Dan Winship
Modified: 2011-09-05 14:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gmain: fix a race condition in g_main_loop_quit() (981 bytes, patch)
2011-09-04 14:44 UTC, Dan Winship
none Details | Review

Description Dan Winship 2011-09-04 14:44:28 UTC
Thread 1                            Thread 2
--------                            --------
g_main_loop_run {
  loop->is_running = TRUE
  g_main_context_iterate {
                                    g_main_loop_quit {
                                      LOCK_CONTEXT
    g_main_context_prepare {
      LOCK_CONTEXT {
        ...                           loop->is_running = FALSE
        ...                           g_main_context_wakeup_unlocked {
        ...                             /* no-op, because
        ...                              * context->poll_waiting is FALSE
        ...                              */
        ...                           }
        ...                           UNLOCK_CONTEXT
      }
      context->poll_waiting = TRUE
    }
    g_poll {
      ...


gio/tests/tls-interaction hits this a lot for some reason.

I'm not sure that the attached patch is the right fix, but it fixes the problem, and doesn't break anything else in "make check"
Comment 1 Dan Winship 2011-09-04 14:44:42 UTC
Created attachment 195627 [details] [review]
gmain: fix a race condition in g_main_loop_quit()

g_main_context_wakeup() needs to signal context->wakeup regardless of
what the context is currently doing, because otherwise the context may
get stuck polling forever without noticing whatever it was supposed to
have woken up for.
Comment 2 Matthias Clasen 2011-09-05 02:12:27 UTC
Is this the same race that is described in bug 632301 ?
Comment 3 Dan Winship 2011-09-05 14:46:17 UTC
yup

*** This bug has been marked as a duplicate of bug 632301 ***