changes to linuxrwlock;
[model-checker-benchmarks.git] / linuxrwlocks / testcase2.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         if (!write_can_lock(&mylock))
17                 return;
18
19         if (write_trylock(&mylock)) {
20                 atomic_store_explicit(&x, 17, relaxed);
21                 write_unlock(&mylock);
22         }
23 }
24
25 static void b(void *obj)
26 {
27         if (write_trylock(&mylock)) {
28                 atomic_store_explicit(&x, 16, relaxed);
29                 write_unlock(&mylock);
30         }
31
32         if (!read_can_lock(&mylock))
33                 return;
34         if (read_trylock(&mylock)) {
35                 atomic_load_explicit(&x, relaxed);
36                 read_unlock(&mylock);
37         }
38 }
39
40 int user_main(int argc, char **argv)
41 {
42         thrd_t t1, t2;
43         atomic_init(&mylock.lock, RW_LOCK_BIAS);
44         atomic_init(&x, 0);
45         atomic_init(&y, 0);
46
47         thrd_create(&t1, (thrd_start_t)&a, NULL);
48         thrd_create(&t2, (thrd_start_t)&b, NULL);
49
50         thrd_join(t1);
51         thrd_join(t2);
52
53         return 0;
54 }