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