tests: Fix non-atomic access to some shared variables

And drop the `volatile` qualifier from the variables, as that doesn’t
help with thread safety.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #600
This commit is contained in:
Philip Withnall 2020-11-11 18:31:01 +00:00
parent 7cdb68713c
commit 1a7f0002a0
2 changed files with 8 additions and 8 deletions

View File

@ -26,7 +26,7 @@ struct _GTestClass
};
static GType my_test_get_type (void);
static volatile gboolean stopping;
static gint stopping; /* (atomic) */
static void my_test_class_init (GTestClass * klass);
static void my_test_init (GTest * test);
@ -101,7 +101,7 @@ run_thread (GTest * test)
{
gint i = 1;
while (!stopping) {
while (!g_atomic_int_get (&stopping)) {
my_test_do_refcount (test);
if ((i++ % 10000) == 0) {
g_print (".");
@ -128,7 +128,7 @@ main (int argc, char **argv)
test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *));
stopping = FALSE;
g_atomic_int_set (&stopping, 0);
for (i = 0; i < n_threads; i++) {
GThread *thread;
@ -141,7 +141,7 @@ main (int argc, char **argv)
}
g_usleep (5000000);
stopping = TRUE;
g_atomic_int_set (&stopping, 1);
g_print ("\nstopping\n");

View File

@ -34,7 +34,7 @@ struct _GTestClass
static GType my_test_get_type (void);
G_DEFINE_TYPE (GTest, my_test, G_TYPE_OBJECT)
static volatile gboolean stopping;
static gint stopping; /* (atomic) */
static void my_test_get_property (GObject *object,
guint prop_id,
@ -140,7 +140,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)
{
@ -170,7 +170,7 @@ main (int argc, char **argv)
test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *));
stopping = FALSE;
g_atomic_int_set (&stopping, 0);
for (i = 0; i < n_threads; i++) {
GThread *thread;
@ -180,7 +180,7 @@ main (int argc, char **argv)
}
g_usleep (30000000);
stopping = TRUE;
g_atomic_int_set (&stopping, 1);
g_print ("\nstopping\n");
/* join all threads */