update rcu comments
[model-checker-benchmarks.git] / linuxrwlocks / testcase1.c
1 #include <stdio.h>
2 #include <threads.h>
3 #include <stdatomic.h>
4
5 #include "librace.h"
6 #include "linuxrwlocks.h"
7
8 rwlock_t mylock;
9 int shareddata;
10
11 atomic_int x, y;
12
13 static void a(void *obj)
14 {
15         write_lock(&mylock);
16         //atomic_store_explicit(&x, 17, memory_order_relaxed);
17         write_unlock(&mylock);
18
19 /*
20
21         if (!write_can_lock(&mylock))
22                 return;
23
24         if (write_trylock(&mylock)) {
25                 atomic_store_explicit(&x, 17, memory_order_relaxed);
26                 write_unlock(&mylock);
27         }
28 */
29 }
30
31 static void b(void *obj)
32 {
33         //if (write_trylock(&mylock)) {
34                 //atomic_store_explicit(&x, 16, memory_order_relaxed);
35         //      write_unlock(&mylock);
36         //}
37
38         read_lock(&mylock);
39         //atomic_load_explicit(&x, memory_order_relaxed);
40         read_unlock(&mylock);
41
42 /*
43         if (write_trylock(&mylock)) {
44                 atomic_store_explicit(&x, 16, memory_order_relaxed);
45                 write_unlock(&mylock);
46         }
47
48         if (!read_can_lock(&mylock))
49                 return;
50         if (read_trylock(&mylock)) {
51                 atomic_load_explicit(&x, memory_order_relaxed);
52                 read_unlock(&mylock);
53         }
54 */
55 }
56
57 int user_main(int argc, char **argv)
58 {
59         thrd_t t1, t2;
60         atomic_init(&mylock.lock, RW_LOCK_BIAS);
61         atomic_init(&x, 0);
62         atomic_init(&y, 0);
63
64         /** @Entry */
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 }