From 9757697e52c8e15f3994a44d7bf4140d65822b32 Mon Sep 17 00:00:00 2001 From: Brian Demsky Date: Mon, 3 Jun 2013 12:02:19 -0700 Subject: [PATCH] Add example from java showing legit satisfaction cycle --- test/csetest.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/csetest.c diff --git a/test/csetest.c b/test/csetest.c new file mode 100644 index 0000000..2058f9c --- /dev/null +++ b/test/csetest.c @@ -0,0 +1,43 @@ +#include +#include +#include + +#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; +} -- 2.34.1