litmus: seq-lock: add MODEL_ASSERT() for the important behavior
[c11tester.git] / test / litmus / message-passing.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_relaxed);
11         y.store(1, std::memory_order_relaxed);
12 }
13
14 static void b(void *obj)
15 {
16         printf("y1: %d\n", y.load(std::memory_order_relaxed));
17         printf("x1: %d\n", x.load(std::memory_order_relaxed));
18 }
19
20 static void c(void *obj)
21 {
22         printf("x2: %d\n", x.load(std::memory_order_relaxed));
23         printf("y2: %d\n", y.load(std::memory_order_relaxed));
24 }
25
26 int user_main(int argc, char **argv)
27 {
28         thrd_t t1, t2, t3;
29
30         atomic_init(&x, 0);
31         atomic_init(&y, 0);
32
33         printf("Main thread: creating 3 threads\n");
34         thrd_create(&t1, (thrd_start_t)&a, NULL);
35         thrd_create(&t2, (thrd_start_t)&b, NULL);
36         thrd_create(&t3, (thrd_start_t)&c, NULL);
37
38         thrd_join(t1);
39         thrd_join(t2);
40         thrd_join(t3);
41         printf("Main thread is finished\n");
42
43         return 0;
44 }