From: Colin Walters Date: Mon, 16 Apr 2012 17:55:02 +0000 (-0400) Subject: tests: Fix race conditions in mainloop/invoke test X-Git-Tag: 2.33.1~110 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3ac2930e1aabeca7dac7a2570cba24591d97e0d2;p=platform%2Fupstream%2Fglib.git tests: Fix race conditions in mainloop/invoke test 1) The test was using GCond incorrectly (it always needs a state variable) 2) The state assertion was racing with the thread; just delete it. All we're really trying to test here is that the invoke runs by the time the thread is gone, and the function has an assertion that it runs in the correct thread. https://bugzilla.gnome.org/show_bug.cgi?id=674213 --- diff --git a/glib/tests/mainloop.c b/glib/tests/mainloop.c index c2ca00c..4986e3d 100644 --- a/glib/tests/mainloop.c +++ b/glib/tests/mainloop.c @@ -255,6 +255,7 @@ call_func (gpointer data) static GMutex mutex; static GCond cond; +static gboolean thread_ready; static gpointer thread_func (gpointer data) @@ -265,6 +266,7 @@ thread_func (gpointer data) g_main_context_push_thread_default (ctx); g_mutex_lock (&mutex); + thread_ready = TRUE; g_cond_signal (&cond); g_mutex_unlock (&mutex); @@ -300,13 +302,14 @@ test_invoke (void) * to another thread */ ctx = g_main_context_new (); - g_mutex_lock (&mutex); thread = g_thread_new ("worker", thread_func, ctx); - g_cond_wait (&cond, &mutex); + g_mutex_lock (&mutex); + while (!thread_ready) + g_cond_wait (&cond, &mutex); + g_mutex_unlock (&mutex); g_main_context_invoke (ctx, func, thread); - g_assert_cmpint (count, ==, 2); g_thread_join (thread); g_assert_cmpint (count, ==, 3);