execution: add const
[model-checker.git] / test / thinair.c
1 #include <stdio.h>
2 #include <threads.h>
3 #include <stdatomic.h>
4
5 #include "librace.h"
6
7 atomic_int x;
8 atomic_int y;
9
10 static void a(void *obj)
11 {
12         int r1=atomic_load_explicit(&x, memory_order_relaxed);
13         atomic_store_explicit(&y, r1, memory_order_relaxed);
14         printf("r1=%d\n",r1);
15 }
16
17 static void b(void *obj)
18 {
19         int r2=atomic_load_explicit(&y, memory_order_relaxed);
20         atomic_store_explicit(&x, r2, memory_order_relaxed);
21         atomic_store_explicit(&x, r2 + 1, memory_order_relaxed);
22         printf("r2=%d\n",r2);
23 }
24
25 int user_main(int argc, char **argv)
26 {
27         thrd_t t1, t2;
28
29         atomic_init(&x, -1);
30         atomic_init(&y, 0);
31
32         printf("Main thread: creating 2 threads\n");
33         thrd_create(&t1, (thrd_start_t)&a, NULL);
34         thrd_create(&t2, (thrd_start_t)&b, NULL);
35
36         thrd_join(t1);
37         thrd_join(t2);
38         printf("Main thread is finished\n");
39
40         return 0;
41 }