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