action: improve "unintialized load" bug print
[model-checker.git] / test / userprog.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(&y, memory_order_relaxed);
13         atomic_store_explicit(&x, 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(&x, memory_order_relaxed);
20         atomic_store_explicit(&y, 42, memory_order_relaxed);
21         printf("r2=%d\n",r2);
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
31         printf("Main thread: creating 2 threads\n");
32         thrd_create(&t1, (thrd_start_t)&a, NULL);
33         thrd_create(&t2, (thrd_start_t)&b, NULL);
34
35         thrd_join(t1);
36         thrd_join(t2);
37         printf("Main thread is finished\n");
38
39         return 0;
40 }