test: add a "pending release sequences" test
authorBrian Norris <banorris@uci.edu>
Wed, 3 Oct 2012 01:52:43 +0000 (18:52 -0700)
committerBrian Norris <banorris@uci.edu>
Wed, 3 Oct 2012 01:55:22 +0000 (18:55 -0700)
This helps test the end-of-execution "pending release sequence"
functionality, as well as other release-sequence-related code. It also
uncovered the regression that was just reverted prior to this.

test/pending-release.c [new file with mode: 0644]

diff --git a/test/pending-release.c b/test/pending-release.c
new file mode 100644 (file)
index 0000000..37433b1
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * This test performs some relaxes, release, acquire opeations on a single
+ * atomic variable. It is designed for creating a difficult set of pending
+ * release sequences to resolve at the end of an execution. However, it
+ * utilizes 6 threads, so it blows up into a lot of executions quickly.
+ */
+
+#include <stdio.h>
+
+#include "libthreads.h"
+#include "librace.h"
+#include "stdatomic.h"
+
+atomic_int x;
+
+static void a(void *obj)
+{
+       atomic_store_explicit(&x, *((int *)obj), memory_order_release);
+       atomic_store_explicit(&x, *((int *)obj) + 1, memory_order_relaxed);
+}
+
+static void b2(void *obj)
+{
+       int r = atomic_load_explicit(&x, memory_order_acquire);
+       printf("r = %u\n", r);
+}
+
+static void b1(void *obj)
+{
+       thrd_t t3, t4;
+       int i = 7;
+       int r = atomic_load_explicit(&x, memory_order_acquire);
+       printf("r = %u\n", r);
+       thrd_create(&t3, (thrd_start_t)&a, &i);
+       thrd_create(&t4, (thrd_start_t)&b2, NULL);
+       thrd_join(t3);
+       thrd_join(t4);
+}
+
+static void c(void *obj)
+{
+       atomic_store_explicit(&x, 22, memory_order_relaxed);
+}
+
+void user_main()
+{
+       thrd_t t1, t2, t5;
+       int i = 4;
+
+       atomic_init(&x, 0);
+
+       thrd_create(&t1, (thrd_start_t)&a, &i);
+       thrd_create(&t2, (thrd_start_t)&b1, NULL);
+       thrd_create(&t5, (thrd_start_t)&c, NULL);
+
+       thrd_join(t1);
+       thrd_join(t2);
+       thrd_join(t5);
+}