new test case
authorBrian Demsky <bdemsky@uci.edu>
Tue, 8 Jan 2013 00:55:00 +0000 (16:55 -0800)
committerBrian Demsky <bdemsky@uci.edu>
Tue, 8 Jan 2013 00:55:00 +0000 (16:55 -0800)
test/rmw2prog.c [new file with mode: 0644]

diff --git a/test/rmw2prog.c b/test/rmw2prog.c
new file mode 100644 (file)
index 0000000..0d03b02
--- /dev/null
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <threads.h>
+#include <stdatomic.h>
+
+#include "librace.h"
+
+atomic_int x;
+atomic_int y;
+
+static void a(void *obj)
+{
+       int v1=atomic_fetch_add_explicit(&x, 1, memory_order_relaxed);
+       int v2=atomic_fetch_add_explicit(&y, 1, memory_order_relaxed);
+       printf("v1 = %d, v2=%d\n", v1, v2);
+}
+
+static void b(void *obj)
+{
+       int v3=atomic_fetch_add_explicit(&y, 1, memory_order_relaxed);
+       int v4=atomic_fetch_add_explicit(&x, 1, memory_order_relaxed);
+       printf("v3 = %d, v4=%d\n", v3, v4);
+}
+
+int user_main(int argc, char **argv)
+{
+       thrd_t t1, t2;
+
+       atomic_init(&x, 0);
+       atomic_init(&y, 0);
+       thrd_create(&t1, (thrd_start_t)&a, NULL);
+       thrd_create(&t2, (thrd_start_t)&b, NULL);
+
+       thrd_join(t1);
+       thrd_join(t2);
+
+       return 0;
+}