test: litmus: add litmus tests from Nitpicking C++
[model-checker.git] / test / litmus / iriw.cc
1 #include <stdio.h>
2 #include <threads.h>
3 #include <atomic>
4
5 std::atomic_int x;
6 std::atomic_int y;
7
8 static void a(void *obj)
9 {
10         x.store(1, std::memory_order_release);
11 }
12
13 static void b(void *obj)
14 {
15         y.store(1, std::memory_order_release);
16 }
17
18 static void c(void *obj)
19 {
20         printf("x1: %d\n", x.load(std::memory_order_relaxed));
21         printf("y1: %d\n", y.load(std::memory_order_relaxed));
22 }
23
24 static void d(void *obj)
25 {
26         printf("y2: %d\n", y.load(std::memory_order_relaxed));
27         printf("x2: %d\n", x.load(std::memory_order_relaxed));
28 }
29
30 int user_main(int argc, char **argv)
31 {
32         thrd_t t1, t2, t3, t4;
33
34         atomic_init(&x, 0);
35         atomic_init(&y, 0);
36
37         printf("Main thread: creating 4 threads\n");
38         thrd_create(&t1, (thrd_start_t)&a, NULL);
39         thrd_create(&t2, (thrd_start_t)&b, NULL);
40         thrd_create(&t3, (thrd_start_t)&c, NULL);
41         thrd_create(&t4, (thrd_start_t)&d, NULL);
42
43         thrd_join(t1);
44         thrd_join(t2);
45         thrd_join(t3);
46         thrd_join(t4);
47         printf("Main thread is finished\n");
48
49         return 0;
50 }