litmus: wrc: add macro for memory ordering
[c11tester.git] / test / wrcs.c
1 #include <stdio.h>
2 #include <threads.h>
3 #include <stdatomic.h>
4 #include "librace.h"
5   atomic_int x1;
6   atomic_int x2;
7   atomic_int x3;
8   atomic_int x4;
9   atomic_int x5;
10   atomic_int x6;
11   atomic_int x7;
12 static void a(void *obj)
13 {
14         atomic_store_explicit(&x1, 1,memory_order_seq_cst);
15 }
16
17 static void b(void *obj)
18 {
19         atomic_load_explicit(&x1, memory_order_seq_cst);
20         atomic_store_explicit(&x2, 1,memory_order_seq_cst);
21 }
22
23 static void c(void *obj)
24 {
25         atomic_load_explicit(&x2, memory_order_seq_cst);
26         atomic_store_explicit(&x3, 1,memory_order_seq_cst);
27 }
28
29 static void d(void *obj)
30 {
31         atomic_load_explicit(&x3, memory_order_seq_cst);
32         atomic_store_explicit(&x4, 1,memory_order_seq_cst);
33 }
34
35 static void e(void *obj)
36 {
37         atomic_load_explicit(&x4, memory_order_seq_cst);
38         atomic_store_explicit(&x5, 1,memory_order_seq_cst);
39 }
40
41 static void f(void *obj)
42 {
43         atomic_load_explicit(&x5, memory_order_seq_cst);
44         atomic_store_explicit(&x6, 1,memory_order_seq_cst);
45 }
46
47 static void g(void *obj)
48 {
49         atomic_load_explicit(&x6, memory_order_seq_cst);
50         atomic_store_explicit(&x7, 1,memory_order_seq_cst);
51 }
52 static void h(void *obj)
53 {
54         atomic_load_explicit(&x7, memory_order_seq_cst);
55         atomic_load_explicit(&x1, memory_order_seq_cst);
56 }
57
58 int user_main(int argc, char **argv)
59 {
60         thrd_t t1, t2, t3, t4, t5, t6, t7, t8;
61         atomic_init(&x1, 0);
62         atomic_init(&x2, 0);
63         atomic_init(&x3, 0);
64         atomic_init(&x4, 0);
65         atomic_init(&x5, 0);
66         atomic_init(&x6, 0);
67         atomic_init(&x7, 0);
68
69
70         thrd_create(&t1, (thrd_start_t)&a, NULL);
71         thrd_create(&t2, (thrd_start_t)&b, NULL);
72         thrd_create(&t3, (thrd_start_t)&c, NULL);
73         thrd_create(&t4, (thrd_start_t)&d, NULL);
74         thrd_create(&t5, (thrd_start_t)&e, NULL);
75         thrd_create(&t6, (thrd_start_t)&f, NULL);
76         thrd_create(&t7, (thrd_start_t)&g, NULL);
77         thrd_create(&t8, (thrd_start_t)&h, NULL);
78
79         thrd_join(t1);
80         thrd_join(t2);
81         thrd_join(t3);
82         thrd_join(t4);
83         thrd_join(t5);
84         thrd_join(t6);
85         thrd_join(t7);
86         thrd_join(t8);
87
88         return 0;
89 }