d3127f392206be6609fd20476a11ad730cfcb7d2
[c11tester.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
9 #include "libthreads.h"
10 #include "librace.h"
11 #include "stdatomic.h"
12
13 atomic_int x;
14
15 static void a(void *obj)
16 {
17         atomic_store_explicit(&x, 1, memory_order_release);
18         atomic_store_explicit(&x, 42, memory_order_relaxed);
19 }
20
21 static void b(void *obj)
22 {
23         int r = atomic_load_explicit(&x, memory_order_acquire);
24         printf("r = %u\n", r);
25 }
26
27 static void c(void *obj)
28 {
29         atomic_store_explicit(&x, 2, memory_order_relaxed);
30 }
31
32 void user_main()
33 {
34         thrd_t t1, t2, t3;
35
36         atomic_init(&x, 0);
37
38         printf("Thread %d: creating 3 threads\n", thrd_current());
39         thrd_create(&t1, (thrd_start_t)&a, NULL);
40         thrd_create(&t2, (thrd_start_t)&b, NULL);
41         thrd_create(&t3, (thrd_start_t)&c, NULL);
42
43         thrd_join(t1);
44         thrd_join(t2);
45         thrd_join(t3);
46         printf("Thread %d is finished\n", thrd_current());
47 }