changes to linuxrwlock;
[model-checker-benchmarks.git] / linuxrwlocks / testcase_full.c
1 #include <stdio.h>
2 #include <threads.h>
3 #include <stdatomic.h>
4 #include "wildcard.h" 
5
6 #include "librace.h"
7 #include "linuxrwlocks-wildcard.h"
8
9 rwlock_t mylock;
10 int shareddata;
11
12 atomic_int x, y;
13
14 static void a(void *obj)
15 {
16         write_lock(&mylock);
17         atomic_store_explicit(&x, 17, relaxed);
18         write_unlock(&mylock);
19         
20         if (!read_can_lock(&mylock))
21                 return;
22         if (read_trylock(&mylock)) {
23                 atomic_load_explicit(&x, relaxed);
24                 read_unlock(&mylock);
25         }
26 }
27
28 static void b(void *obj)
29 {
30
31         if (write_trylock(&mylock)) {
32                 atomic_store_explicit(&x, 16, relaxed);
33                 write_unlock(&mylock);
34         }
35         
36         read_lock(&mylock);
37         atomic_load_explicit(&x, relaxed);
38         read_unlock(&mylock);
39 }
40
41 int user_main(int argc, char **argv)
42 {
43         thrd_t t1, t2;
44         atomic_init(&mylock.lock, RW_LOCK_BIAS);
45         atomic_init(&x, 0);
46         atomic_init(&y, 0);
47
48         thrd_create(&t1, (thrd_start_t)&a, NULL);
49         thrd_create(&t2, (thrd_start_t)&b, NULL);
50
51         thrd_join(t1);
52         thrd_join(t2);
53
54         return 0;
55 }