test: insanesync: consolidate lines
[cdsspec-compiler.git] / test / double-relseq.c
1 /*
2  * This test performs some relaxed, release, acquire opeations on a single
3  * atomic variable. It can give some rough idea of release sequence support but
4  * probably should be improved to give better information.
5  *
6  * This test tries to establish two release sequences, where we should always
7  * either establish both or establish neither. (Note that this is only true for
8  * a few executions of interest, where both load-acquire's read from the same
9  * write.)
10  */
11
12 #include <stdio.h>
13 #include <threads.h>
14 #include <stdatomic.h>
15
16 #include "librace.h"
17
18 atomic_int x;
19 int var = 0;
20
21 static void a(void *obj)
22 {
23         store_32(&var, 1);
24         atomic_store_explicit(&x, 1, memory_order_release);
25         atomic_store_explicit(&x, 42, memory_order_relaxed);
26 }
27
28 static void b(void *obj)
29 {
30         int r = atomic_load_explicit(&x, memory_order_acquire);
31         printf("r = %d\n", r);
32         printf("load %d\n", load_32(&var));
33 }
34
35 static void c(void *obj)
36 {
37         atomic_store_explicit(&x, 2, memory_order_relaxed);
38 }
39
40 int user_main(int argc, char **argv)
41 {
42         thrd_t t1, t2, t3, t4;
43
44         atomic_init(&x, 0);
45
46         printf("Main thread: creating 4 threads\n");
47         thrd_create(&t1, (thrd_start_t)&a, NULL);
48         thrd_create(&t2, (thrd_start_t)&b, NULL);
49         thrd_create(&t3, (thrd_start_t)&b, NULL);
50         thrd_create(&t4, (thrd_start_t)&c, NULL);
51
52         thrd_join(t1);
53         thrd_join(t2);
54         thrd_join(t3);
55         thrd_join(t4);
56         printf("Main thread is finished\n");
57
58         return 0;
59 }