diff --git a/glib/tests/asyncqueue.c b/glib/tests/asyncqueue.c index 80ada3e00..2fcb23c66 100644 --- a/glib/tests/asyncqueue.c +++ b/glib/tests/asyncqueue.c @@ -136,9 +136,8 @@ test_async_queue_destroy (void) static GAsyncQueue *global_queue; static GThread *threads[10]; -static gint counts[10]; -static gint sums[10]; -static gint total; +static gint counts[10]; /* (atomic) */ +static gint sums[10]; /* (atomic) */ static gpointer thread_func (gpointer data) @@ -153,8 +152,8 @@ thread_func (gpointer data) if (value == -1) break; - counts[pos]++; - sums[pos] += value; + g_atomic_int_inc (&counts[pos]); + g_atomic_int_add (&sums[pos], value); g_usleep (1000); } @@ -168,6 +167,7 @@ test_async_queue_threads (void) gint i, j; gint s, c; gint value; + int total = 0; global_queue = g_async_queue_new (); @@ -200,10 +200,13 @@ test_async_queue_threads (void) for (i = 0; i < 10; i++) { - g_assert_cmpint (sums[i], >, 0); - g_assert_cmpint (counts[i], >, 0); - s += sums[i]; - c += counts[i]; + int sums_i = g_atomic_int_get (&sums[i]); + int counts_i = g_atomic_int_get (&counts[i]); + + g_assert_cmpint (sums_i, >, 0); + g_assert_cmpint (counts_i, >, 0); + s += sums_i; + c += counts_i; } g_assert_cmpint (s, ==, total);