More fuzzing changes
[c11tester.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 int z;
10
11 static void a(void *obj)
12 {
13         int r1=atomic_load_explicit(&y, memory_order_relaxed);
14         atomic_store_explicit(&x, r1, memory_order_relaxed);
15 //      z = 1;
16         printf("r1=%d\n",r1);
17 }
18
19 static void b(void *obj)
20 {
21         int r2=atomic_load_explicit(&x, memory_order_relaxed);
22         atomic_store_explicit(&y, 42, memory_order_relaxed);
23 //      z = 2;
24         printf("r2=%d\n",r2);
25 }
26
27 int user_main(int argc, char **argv)
28 {
29         thrd_t t1, t2;
30
31         atomic_init(&x, 30);
32         atomic_init(&y, 0);
33
34         printf("Main thread: creating 2 threads\n");
35         thrd_create(&t1, (thrd_start_t)&a, NULL);
36         thrd_create(&t2, (thrd_start_t)&b, NULL);
37
38         thrd_join(t1);
39         thrd_join(t2);
40         printf("Main thread is finished\n");
41
42         return 0;
43 }