X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=linuxrwlocks%2Fmain.c;fp=linuxrwlocks%2Fmain.c;h=a81aa9c7e9e918c584ca8f3dbe68b68277055bde;hb=1e4cd56e5cf72f7cb6dddb2990183f050afc4cbc;hp=0000000000000000000000000000000000000000;hpb=7ca8c7d4c3d13ce31873200b12403bb4ea7e4195;p=model-checker-benchmarks.git diff --git a/linuxrwlocks/main.c b/linuxrwlocks/main.c new file mode 100644 index 0000000..a81aa9c --- /dev/null +++ b/linuxrwlocks/main.c @@ -0,0 +1,45 @@ +#include +#include +#include + +#include "librace.h" +#include "linuxrwlocks.h" + +rwlock_t mylock; +int shareddata; + +atomic_int x, y; + +static void a(void *obj) +{ + int i; + for(i = 0; i < 2; i++) { + if ((i % 2) == 0) { + read_lock(&mylock); + load_32(&shareddata); + read_unlock(&mylock); + } else { + write_lock(&mylock); + store_32(&shareddata,(unsigned int)i); + write_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)&a, NULL); + + thrd_join(t1); + thrd_join(t2); + + return 0; +}