barrier with weaker inferences & notes in comment
[model-checker-benchmarks.git] / linuxrwlocks / linuxrwlocks.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 static void a(void *obj)
12 {
13         int i;
14         for(i = 0; i < 2; i++) {
15                 if ((i % 2) == 0) {
16                         read_lock(&mylock);
17                         load_32(&shareddata);
18                         read_unlock(&mylock);
19                 } else {
20                         write_lock(&mylock);
21                         store_32(&shareddata,(unsigned int)i);
22                         write_unlock(&mylock);
23                 }
24         }
25 }
26
27 int user_main(int argc, char **argv)
28 {
29         thrd_t t1, t2;
30         atomic_init(&mylock.lock, RW_LOCK_BIAS);
31
32         thrd_create(&t1, (thrd_start_t)&a, NULL);
33         thrd_create(&t2, (thrd_start_t)&a, NULL);
34
35         thrd_join(t1);
36         thrd_join(t2);
37
38         return 0;
39 }