Fix snapshot code
[model-checker.git] / test / rmw2prog.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 v1=atomic_fetch_add_explicit(&x, 1, memory_order_relaxed);
13         int v2=atomic_fetch_add_explicit(&y, 1, memory_order_relaxed);
14         printf("v1 = %d, v2=%d\n", v1, v2);
15 }
16
17 static void b(void *obj)
18 {
19         int v3=atomic_fetch_add_explicit(&y, 1, memory_order_relaxed);
20         int v4=atomic_fetch_add_explicit(&x, 1, memory_order_relaxed);
21         printf("v3 = %d, v4=%d\n", v3, v4);
22 }
23
24 int user_main(int argc, char **argv)
25 {
26         thrd_t t1, t2;
27
28         atomic_init(&x, 0);
29         atomic_init(&y, 0);
30         thrd_create(&t1, (thrd_start_t)&a, NULL);
31         thrd_create(&t2, (thrd_start_t)&b, NULL);
32
33         thrd_join(t1);
34         thrd_join(t2);
35
36         return 0;
37 }