]> Savannah Git Hosting - gnulib.git/commitdiff
cond tests: Improve multithread-safety.
authorBruno Haible <bruno@clisp.org>
Fri, 28 Jun 2024 19:51:40 +0000 (21:51 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 28 Jun 2024 20:39:49 +0000 (22:39 +0200)
* tests/test-cnd.c (cond_value, cond_timed_out): Mark as volatile.
* tests/test-cond.c (cond_value, cond_timed_out): Likewise.
* tests/test-pthread-cond.c (cond_value, cond_timed_out): Likewise.

ChangeLog
tests/test-cnd.c
tests/test-cond.c
tests/test-pthread-cond.c

index a309c59a503f04e03b650dc593af8f7b22b824a3..75f9d19a4398467535d3c8248238fa719b4e6398 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2024-06-28  Bruno Haible  <bruno@clisp.org>
 
+       cond tests: Improve multithread-safety.
+       * tests/test-cnd.c (cond_value, cond_timed_out): Mark as volatile.
+       * tests/test-cond.c (cond_value, cond_timed_out): Likewise.
+       * tests/test-pthread-cond.c (cond_value, cond_timed_out): Likewise.
+
        cond tests: Improve comments.
        * tests/test-cnd.c: Improve comments.
        (cond_value): Remove initializer.
index 0aca5cdf07be172449f49cbdb3dee9b8f711582a..730c879c49b443584ad397c1ae668546cfa7033b 100644 (file)
 /*
  * Condition check
  */
-static int cond_value;
+
+/* Marked volatile so that different threads see the same value.  This is
+   good enough in practice, although in theory stdatomic.h should be used.  */
+static int volatile cond_value;
 static cnd_t condtest;
 static mtx_t lockcond;
 
@@ -121,7 +124,10 @@ test_cnd_wait ()
 /*
  * Timed Condition check
  */
-static int cond_timed_out;
+
+/* Marked volatile so that different threads see the same value.  This is
+   good enough in practice, although in theory stdatomic.h should be used.  */
+static int volatile cond_timed_out;
 
 /* Stores in *TS the current time plus 1 second.  */
 static void
@@ -193,6 +199,7 @@ test_cnd_timedwait (void)
     abort ();
 }
 
+
 int
 main ()
 {
index eb92580e448680d1bb296dadf13d768f4a7a6f7c..80d696a5d8c8b07b62912e55c76f06218b0e123f 100644 (file)
 /*
  * Condition check
  */
-static int cond_value;
+
+/* Marked volatile so that different threads see the same value.  This is
+   good enough in practice, although in theory stdatomic.h should be used.  */
+static int volatile cond_value;
 gl_cond_define_initialized(static, condtest)
 gl_lock_define_initialized(static, lockcond)
 
@@ -116,7 +119,10 @@ test_cond ()
 /*
  * Timed Condition check
  */
-static int cond_timed_out;
+
+/* Marked volatile so that different threads see the same value.  This is
+   good enough in practice, although in theory stdatomic.h should be used.  */
+static int volatile cond_timed_out;
 
 /* Stores in *TS the current time plus 1 second.  */
 static void
@@ -183,6 +189,7 @@ test_timedcond (void)
     abort ();
 }
 
+
 int
 main ()
 {
index 40cba9e548f91fc0ca7952f53e38da40bc574c1f..98c291c24c0488b008369a7fe747b05d7b4333e1 100644 (file)
 /*
  * Condition check
  */
-static int cond_value;
+
+/* Marked volatile so that different threads see the same value.  This is
+   good enough in practice, although in theory stdatomic.h should be used.  */
+static int volatile cond_value;
 static pthread_cond_t condtest;
 static pthread_mutex_t lockcond;
 
@@ -126,7 +129,10 @@ test_pthread_cond_wait ()
 /*
  * Timed Condition check
  */
-static int cond_timed_out;
+
+/* Marked volatile so that different threads see the same value.  This is
+   good enough in practice, although in theory stdatomic.h should be used.  */
+static int volatile cond_timed_out;
 
 /* Stores in *TS the current time plus 1 second.  */
 static void
@@ -199,6 +205,7 @@ test_pthread_cond_timedwait (void)
     abort ();
 }
 
+
 int
 main ()
 {