From: Brian Demsky Date: Mon, 3 Jun 2013 19:02:19 +0000 (-0700) Subject: Add example from java showing legit satisfaction cycle X-Git-Tag: oopsla2013-final~16 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=commitdiff_plain;h=9757697e52c8e15f3994a44d7bf4140d65822b32;hp=074f97c4bb71c6d9851daec95eae14cf1c3bab25 Add example from java showing legit satisfaction cycle --- 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; +}