Add example from java showing legit satisfaction cycle
authorBrian Demsky <bdemsky@uci.edu>
Mon, 3 Jun 2013 19:02:19 +0000 (12:02 -0700)
committerBrian Demsky <bdemsky@uci.edu>
Mon, 3 Jun 2013 19:02:19 +0000 (12:02 -0700)
test/csetest.c [new file with mode: 0644]

diff --git a/test/csetest.c b/test/csetest.c
new file mode 100644 (file)
index 0000000..2058f9c
--- /dev/null
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <threads.h>
+#include <stdatomic.h>
+
+#include "librace.h"
+
+atomic_int a;
+atomic_int b;
+
+static void r(void *obj)
+{
+       int r1=atomic_load_explicit(&a, memory_order_relaxed);
+       int r2=atomic_load_explicit(&a, memory_order_relaxed);
+       if (r1==r2)
+               atomic_store_explicit(&b, 2, memory_order_relaxed);
+       printf("r1=%d\n",r1);
+       printf("r2=%d\n",r2);
+}
+
+static void s(void *obj)
+{
+       int r3=atomic_load_explicit(&b, memory_order_relaxed);
+       atomic_store_explicit(&a, r3, memory_order_relaxed);
+       printf("r3=%d\n",r3);
+}
+
+int user_main(int argc, char **argv)
+{
+       thrd_t t1, t2;
+
+       atomic_init(&a, 0);
+       atomic_init(&b, 1);
+
+       printf("Main thread: creating 2 threads\n");
+       thrd_create(&t1, (thrd_start_t)&r, NULL);
+       thrd_create(&t2, (thrd_start_t)&s, NULL);
+
+       thrd_join(t1);
+       thrd_join(t2);
+       printf("Main thread is finished\n");
+
+       return 0;
+}