test: rmwprog: add MODEL_ASSERT
[c11tester.git] / test / rmwprog.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <threads.h>
4 #include <stdatomic.h>
5
6 #include "librace.h"
7 #include "model-assert.h"
8
9 atomic_int x;
10 static int N = 2;
11
12 static void a(void *obj)
13 {
14         int i;
15         for (i = 0; i < N; i++)
16                 atomic_fetch_add_explicit(&x, 1, memory_order_relaxed);
17 }
18
19 int user_main(int argc, char **argv)
20 {
21         thrd_t t1, t2;
22
23         if (argc > 1)
24                 N = atoi(argv[1]);
25
26         atomic_init(&x, 0);
27         thrd_create(&t1, (thrd_start_t)&a, NULL);
28         thrd_create(&t2, (thrd_start_t)&a, NULL);
29
30         thrd_join(t1);
31         thrd_join(t2);
32
33         MODEL_ASSERT(atomic_load(&x) == N * 2);
34
35         return 0;
36 }