[glib: 7/9] tests: Synchronize access to stopping flag



commit d75605e866e1049223c88ffdbd2f78be07423812
Author: Tomasz Miąsko <tomasz miasko gmail com>
Date:   Fri Feb 22 00:00:00 2019 +0000

    tests: Synchronize access to stopping flag

 tests/refcount/properties.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/tests/refcount/properties.c b/tests/refcount/properties.c
index c68234216..376d9313c 100644
--- a/tests/refcount/properties.c
+++ b/tests/refcount/properties.c
@@ -35,7 +35,7 @@ struct _GTestClass
 };
 
 static GType my_test_get_type (void);
-static volatile gboolean stopping;
+static gboolean stopping;
 
 static void my_test_class_init (GTestClass * klass);
 static void my_test_init (GTest * test);
@@ -177,7 +177,7 @@ run_thread (GTest * test)
 {
   gint i = 1;
   
-  while (!stopping) {
+  while (!g_atomic_int_get (&stopping)) {
     my_test_do_property (test);
     if ((i++ % 10000) == 0)
       {
@@ -210,14 +210,14 @@ main (int argc, char **argv)
     g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL);
   }
 
-  stopping = FALSE;
+  g_atomic_int_set (&stopping, FALSE);
 
   for (i = 0; i < N_THREADS; i++)
     test_threads[i] = g_thread_create ((GThreadFunc) run_thread, test_objects[i], TRUE, NULL);
 
   g_usleep (3000000);
 
-  stopping = TRUE;
+  g_atomic_int_set (&stopping, TRUE);
   g_print ("\nstopping\n");
 
   /* join all threads */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]