* 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.
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.
/*
* 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;
/*
* 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
abort ();
}
+
int
main ()
{
/*
* 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)
/*
* 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
abort ();
}
+
int
main ()
{
/*
* 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;
/*
* 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
abort ();
}
+
int
main ()
{