test: insanesync: consolidate lines
[cdsspec-compiler.git] / test / double-read-fv.c
1 /*
2  * Try to read the same value as a future value twice.
3  *
4  * This test should be able to see r1 = r2 = 42. Currently, we never see that
5  * (as of 2/21/13) because the r2 load won't have a potential future value of
6  * 42 at the same time as r1, due to our scheduling (the loads for r1 and r2
7  * must occur before the write of x = 42).
8  *
9  * Note that the atomic_int y is simply used to aid in forcing a particularly
10  * interesting scheduling. It is superfluous.
11  */
12 #include <stdio.h>
13 #include <threads.h>
14 #include <stdatomic.h>
15
16 #include "librace.h"
17
18 atomic_int x;
19 atomic_int y;
20
21 static void a(void *obj)
22 {
23         int r1 = atomic_load_explicit(&x, memory_order_relaxed);
24         int r2 = atomic_load_explicit(&x, memory_order_relaxed);
25         printf("r1 = %d, r2 = %d\n", r1, r2);
26 }
27
28 static void b(void *obj)
29 {
30         atomic_store_explicit(&y, 43, memory_order_relaxed);
31         atomic_store_explicit(&x, 42, memory_order_relaxed);
32 }
33
34 int user_main(int argc, char **argv)
35 {
36         thrd_t t1, t2;
37
38         atomic_init(&x, 0);
39         atomic_init(&y, 0);
40
41         printf("Main thread: creating 2 threads\n");
42         thrd_create(&t1, (thrd_start_t)&a, NULL);
43         thrd_create(&t2, (thrd_start_t)&b, NULL);
44
45         thrd_join(t1);
46         thrd_join(t2);
47         printf("Main thread is finished\n");
48
49         return 0;
50 }