From c27cd2246700b671d0efb1cafd8bbc1ef2c90535 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Fri, 14 Sep 2012 13:12:42 -0700 Subject: [PATCH] tests: add releaseseq test Very simple release/acquire test, with some relaxed writes thrown in. The test is semi-useful and can certainly be tweaked a bit. --- test/releaseseq.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/releaseseq.c diff --git a/test/releaseseq.c b/test/releaseseq.c new file mode 100644 index 0000000..d3127f3 --- /dev/null +++ b/test/releaseseq.c @@ -0,0 +1,47 @@ +/* + * This test performs some relaxes, release, acquire opeations on a single + * atomic variable. It can give some rough idea of release sequence support but + * probably should be improved to give better information. + */ + +#include + +#include "libthreads.h" +#include "librace.h" +#include "stdatomic.h" + +atomic_int x; + +static void a(void *obj) +{ + atomic_store_explicit(&x, 1, memory_order_release); + atomic_store_explicit(&x, 42, memory_order_relaxed); +} + +static void b(void *obj) +{ + int r = atomic_load_explicit(&x, memory_order_acquire); + printf("r = %u\n", r); +} + +static void c(void *obj) +{ + atomic_store_explicit(&x, 2, memory_order_relaxed); +} + +void user_main() +{ + thrd_t t1, t2, t3; + + atomic_init(&x, 0); + + printf("Thread %d: creating 3 threads\n", thrd_current()); + thrd_create(&t1, (thrd_start_t)&a, NULL); + thrd_create(&t2, (thrd_start_t)&b, NULL); + thrd_create(&t3, (thrd_start_t)&c, NULL); + + thrd_join(t1); + thrd_join(t2); + thrd_join(t3); + printf("Thread %d is finished\n", thrd_current()); +} -- 2.34.1