X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=linuxrwlocks%2Ftestcase1.c;fp=linuxrwlocks%2Ftestcase1.c;h=8051cdcac819b4989b50b9a58afd7f5f9dab74e7;hb=1e4cd56e5cf72f7cb6dddb2990183f050afc4cbc;hp=0000000000000000000000000000000000000000;hpb=7ca8c7d4c3d13ce31873200b12403bb4ea7e4195;p=model-checker-benchmarks.git diff --git a/linuxrwlocks/testcase1.c b/linuxrwlocks/testcase1.c new file mode 100644 index 0000000..8051cdc --- /dev/null +++ b/linuxrwlocks/testcase1.c @@ -0,0 +1,72 @@ +#include +#include +#include + +#include "librace.h" +#include "linuxrwlocks.h" + +rwlock_t mylock; +int shareddata; + +atomic_int x, y; + +static void a(void *obj) +{ + write_lock(&mylock); + //atomic_store_explicit(&x, 17, memory_order_relaxed); + write_unlock(&mylock); + +/* + + if (!write_can_lock(&mylock)) + return; + + if (write_trylock(&mylock)) { + atomic_store_explicit(&x, 17, memory_order_relaxed); + write_unlock(&mylock); + } +*/ +} + +static void b(void *obj) +{ + //if (write_trylock(&mylock)) { + //atomic_store_explicit(&x, 16, memory_order_relaxed); + // write_unlock(&mylock); + //} + + read_lock(&mylock); + //atomic_load_explicit(&x, memory_order_relaxed); + read_unlock(&mylock); + +/* + if (write_trylock(&mylock)) { + atomic_store_explicit(&x, 16, memory_order_relaxed); + write_unlock(&mylock); + } + + if (!read_can_lock(&mylock)) + return; + if (read_trylock(&mylock)) { + atomic_load_explicit(&x, memory_order_relaxed); + read_unlock(&mylock); + } +*/ +} + +int user_main(int argc, char **argv) +{ + thrd_t t1, t2; + atomic_init(&mylock.lock, RW_LOCK_BIAS); + atomic_init(&x, 0); + atomic_init(&y, 0); + + /** @Entry */ + thrd_create(&t1, (thrd_start_t)&a, NULL); + thrd_create(&t2, (thrd_start_t)&b, NULL); + + thrd_join(t1); + thrd_join(t2); + + return 0; +}