fix bug by changing MEMALLOC to SNAPSHOTALLOC
[c11tester.git] / test / rmw2prog.c
1 #include <stdio.h>
2 #include <threads.h>
3 #include <stdatomic.h>
4
5 #include "librace.h"
6
7 atomic_short x;
8 atomic_short y;
9
10 static void a(void *obj)
11 {
12         short desire = 315;
13         short expected = 0;
14         short * pt = &expected;
15
16         printf("expected was %d, but x is %d\n", expected, x);
17
18         short v1 = atomic_compare_exchange_weak_explicit(&x, pt, desire, memory_order_relaxed, memory_order_acquire);
19         printf("Then v1 = %d, x = %d\n", v1, x);
20         printf("expected: %d\n", expected);
21 /*
22         short v1 = atomic_exchange_explicit(&x, 8, memory_order_relaxed);
23         short v2 = atomic_exchange_explicit(&x, -10, memory_order_relaxed);
24         short v3 = atomic_load_explicit(&x, memory_order_relaxed);
25         printf("v1 = %d, v2 = %d, v3 = %d\n", v1, v2, v3);
26  */
27 }
28
29 static void b(void *obj)
30 {
31         int v3=atomic_fetch_add_explicit(&y, 2, memory_order_relaxed);
32         int v4=atomic_fetch_add_explicit(&x, -5, memory_order_relaxed);
33         printf("v3 = %d, v4=%d\n", v3, v4);
34 }
35
36 int user_main(int argc, char **argv)
37 {
38         thrd_t t1, t2;
39
40         atomic_init(&x, 0);
41         atomic_init(&y, 0);
42
43         thrd_create(&t1, (thrd_start_t)&a, NULL);
44 //      thrd_create(&t2, (thrd_start_t)&b, NULL);
45
46         thrd_join(t1);
47 //      thrd_join(t2);
48
49         return 0;
50 }