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