Fix snapshot code
[model-checker.git] / test / iriw_wildcard.cc
1 /**
2  * @file iriw.cc
3  * @brief Independent read and independent write test
4  */
5
6 #include <atomic>
7 #include <threads.h>
8 #include <stdio.h>
9
10 #include "wildcard.h"
11 #include "model-assert.h"
12
13 using namespace std;
14
15 atomic_int x, y;
16 int r1, r2, r3, r4; /* "local" variables */
17
18 static void a(void *obj)
19 {
20         x.store(1, wildcard(1));
21 }
22
23 static void b(void *obj)
24 {
25         y.store(1, wildcard(2));
26 }
27
28 static void c(void *obj)
29 {
30         r1 = x.load(wildcard(3));
31         r2 = y.load(wildcard(4));
32 }
33
34 static void d(void *obj)
35 {
36         r3 = y.load(wildcard(5));
37         r4 = x.load(wildcard(6));
38 }
39
40
41 int user_main(int argc, char **argv)
42 {
43         thrd_t t1, t2, t3, t4;
44
45         atomic_init(&x, 0);
46         atomic_init(&y, 0);
47
48         printf("Main thread: creating 4 threads\n");
49         thrd_create(&t1, (thrd_start_t)&a, NULL);
50         thrd_create(&t2, (thrd_start_t)&b, NULL);
51         thrd_create(&t3, (thrd_start_t)&c, NULL);
52         thrd_create(&t4, (thrd_start_t)&d, NULL);
53
54         thrd_join(t1);
55         thrd_join(t2);
56         thrd_join(t3);
57         thrd_join(t4);
58         printf("Main thread is finished\n");
59
60         /*
61          * This condition should not be hit if the execution is SC */
62         bool sc = (r1 == 1 && r2 == 0 && r3 == 1 && r4 == 0);
63         //MODEL_ASSERT(!sc);
64
65         return 0;
66 }