Commit state of repository at time of OOPSLA 2015 submission.
[satcheck.git] / test / function_microbenchmarks.c
1 #include <stdio.h>
2 #include <threads.h>
3 #include <stdatomic.h>
4
5 #include "libinterface.h"
6
7 int x;
8 int y;
9 int gr1;
10 int gr2;
11
12 static void a(void *obj)
13 {
14     int r1=load_32(&y);
15     if (r1) {
16         r1=42;
17         store_32(&x, r1);
18     } else {
19         r1=0;
20     }
21
22     store_32(&x, r1);
23
24     int r2 = load_32(&x);
25     int cond = r1 == r2;
26     if (cond) {
27         r2++;
28     }
29
30     int cas_value = rmw_32(CAS, &x, r1, r2);
31     int cas_value1;
32     cas_value1 = rmw_32(ADD, &y, r1, r1);
33 }
34
35 int user_main(int argc, char **argv)
36 {
37     thrd_t t1; thrd_t t2;
38
39     store_32(&x, 0);
40     store_32(&y, 0);
41
42     printf("Main thread: creating 2 threads\n");
43     thrd_create(&t1, (thrd_start_t)&a, NULL);
44
45     thrd_join(t1);
46     printf("Main thread is finished\n");
47     int lgr1=load_32(&gr1);
48
49     int lgr2=load_32(&gr2);
50     if (lgr1==42) {
51         if (lgr2==42) {
52         } else {
53         }
54     } else {
55     }
56
57     return 0;
58 }