Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame^] | 1 | From 1a7f0002a052725fb646e136fadd5dad66222d7f Mon Sep 17 00:00:00 2001 |
| 2 | From: Philip Withnall <pwithnall@endlessos.org> |
| 3 | Date: Wed, 11 Nov 2020 18:31:01 +0000 |
| 4 | Subject: [PATCH 12/29] tests: Fix non-atomic access to some shared variables |
| 5 | MIME-Version: 1.0 |
| 6 | Content-Type: text/plain; charset=UTF-8 |
| 7 | Content-Transfer-Encoding: 8bit |
| 8 | |
| 9 | And drop the `volatile` qualifier from the variables, as that doesn’t |
| 10 | help with thread safety. |
| 11 | |
| 12 | Signed-off-by: Philip Withnall <pwithnall@endlessos.org> |
| 13 | |
| 14 | Helps: #600 |
| 15 | Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1719] |
| 16 | --- |
| 17 | tests/refcount/objects.c | 8 ++++---- |
| 18 | tests/refcount/properties3.c | 8 ++++---- |
| 19 | 2 files changed, 8 insertions(+), 8 deletions(-) |
| 20 | |
| 21 | diff --git a/tests/refcount/objects.c b/tests/refcount/objects.c |
| 22 | index 963766d00..0c471a42b 100644 |
| 23 | --- a/tests/refcount/objects.c |
| 24 | +++ b/tests/refcount/objects.c |
| 25 | @@ -26,7 +26,7 @@ struct _GTestClass |
| 26 | }; |
| 27 | |
| 28 | static GType my_test_get_type (void); |
| 29 | -static volatile gboolean stopping; |
| 30 | +static gint stopping; /* (atomic) */ |
| 31 | |
| 32 | static void my_test_class_init (GTestClass * klass); |
| 33 | static void my_test_init (GTest * test); |
| 34 | @@ -101,7 +101,7 @@ run_thread (GTest * test) |
| 35 | { |
| 36 | gint i = 1; |
| 37 | |
| 38 | - while (!stopping) { |
| 39 | + while (!g_atomic_int_get (&stopping)) { |
| 40 | my_test_do_refcount (test); |
| 41 | if ((i++ % 10000) == 0) { |
| 42 | g_print ("."); |
| 43 | @@ -128,7 +128,7 @@ main (int argc, char **argv) |
| 44 | |
| 45 | test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *)); |
| 46 | |
| 47 | - stopping = FALSE; |
| 48 | + g_atomic_int_set (&stopping, 0); |
| 49 | |
| 50 | for (i = 0; i < n_threads; i++) { |
| 51 | GThread *thread; |
| 52 | @@ -141,7 +141,7 @@ main (int argc, char **argv) |
| 53 | } |
| 54 | g_usleep (5000000); |
| 55 | |
| 56 | - stopping = TRUE; |
| 57 | + g_atomic_int_set (&stopping, 1); |
| 58 | |
| 59 | g_print ("\nstopping\n"); |
| 60 | |
| 61 | diff --git a/tests/refcount/properties3.c b/tests/refcount/properties3.c |
| 62 | index bc8820661..31f26a46e 100644 |
| 63 | --- a/tests/refcount/properties3.c |
| 64 | +++ b/tests/refcount/properties3.c |
| 65 | @@ -34,7 +34,7 @@ struct _GTestClass |
| 66 | static GType my_test_get_type (void); |
| 67 | G_DEFINE_TYPE (GTest, my_test, G_TYPE_OBJECT) |
| 68 | |
| 69 | -static volatile gboolean stopping; |
| 70 | +static gint stopping; /* (atomic) */ |
| 71 | |
| 72 | static void my_test_get_property (GObject *object, |
| 73 | guint prop_id, |
| 74 | @@ -140,7 +140,7 @@ run_thread (GTest * test) |
| 75 | { |
| 76 | gint i = 1; |
| 77 | |
| 78 | - while (!stopping) { |
| 79 | + while (!g_atomic_int_get (&stopping)) { |
| 80 | my_test_do_property (test); |
| 81 | if ((i++ % 10000) == 0) |
| 82 | { |
| 83 | @@ -170,7 +170,7 @@ main (int argc, char **argv) |
| 84 | |
| 85 | test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *)); |
| 86 | |
| 87 | - stopping = FALSE; |
| 88 | + g_atomic_int_set (&stopping, 0); |
| 89 | |
| 90 | for (i = 0; i < n_threads; i++) { |
| 91 | GThread *thread; |
| 92 | @@ -180,7 +180,7 @@ main (int argc, char **argv) |
| 93 | } |
| 94 | g_usleep (30000000); |
| 95 | |
| 96 | - stopping = TRUE; |
| 97 | + g_atomic_int_set (&stopping, 1); |
| 98 | g_print ("\nstopping\n"); |
| 99 | |
| 100 | /* join all threads */ |
| 101 | -- |
| 102 | 2.30.1 |
| 103 | |