The CDSSpec checker's benchmarks
[model-checker-benchmarks.git] / linuxrwlocks / main.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         int i;
16         for(i = 0; i < 2; i++) {
17                 if ((i % 2) == 0) {
18                         read_lock(&mylock);
19                         load_32(&shareddata);
20                         read_unlock(&mylock);
21                 } else {
22                         write_lock(&mylock);
23                         store_32(&shareddata,(unsigned int)i);
24                         write_unlock(&mylock);
25                 }
26         }
27 }
28
29
30 int user_main(int argc, char **argv)
31 {
32         thrd_t t1, t2;
33         atomic_init(&mylock.lock, RW_LOCK_BIAS);
34         atomic_init(&x, 0);
35         atomic_init(&y, 0);
36
37         /** @Entry */
38         thrd_create(&t1, (thrd_start_t)&a, NULL);
39         thrd_create(&t2, (thrd_start_t)&a, NULL);
40
41         thrd_join(t1);
42         thrd_join(t2);
43
44         return 0;
45 }