tests: use <stdatomic.h>
[model-checker.git] / test / releaseseq.c
1 /*
2  * This test performs some relaxes, 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
7 #include <stdio.h>
8 #include <threads.h>
9 #include <stdatomic.h>
10
11 #include "librace.h"
12
13 atomic_int x;
14 int var = 0;
15
16 static void a(void *obj)
17 {
18         store_32(&var, 1);
19         atomic_store_explicit(&x, 1, memory_order_release);
20         atomic_store_explicit(&x, 42, memory_order_relaxed);
21 }
22
23 static void b(void *obj)
24 {
25         int r = atomic_load_explicit(&x, memory_order_acquire);
26         printf("r = %u\n", r);
27         printf("load %d\n", load_32(&var));
28 }
29
30 static void c(void *obj)
31 {
32         atomic_store_explicit(&x, 2, memory_order_relaxed);
33 }
34
35 int user_main(int argc, char **argv)
36 {
37         thrd_t t1, t2, t3;
38
39         atomic_init(&x, 0);
40
41         printf("Thread %d: creating 3 threads\n", thrd_current());
42         thrd_create(&t1, (thrd_start_t)&a, NULL);
43         thrd_create(&t2, (thrd_start_t)&b, NULL);
44         thrd_create(&t3, (thrd_start_t)&c, NULL);
45
46         thrd_join(t1);
47         thrd_join(t2);
48         thrd_join(t3);
49         printf("Thread %d is finished\n", thrd_current());
50
51         return 0;
52 }