Bug fix for removing ATOMIC_WAIT actions
[c11tester.git] / pthread_test / iriw_wildcard.cc
1 /**
2  * @file iriw.cc
3  * @brief Independent read and independent write test
4  */
5
6 #include <atomic>
7 #include <pthread.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         return NULL;
22 }
23
24 static void *b(void *obj)
25 {
26         y.store(1, wildcard(2));
27         return NULL;
28 }
29
30 static void *c(void *obj)
31 {
32         r1 = x.load(wildcard(3));
33         r2 = y.load(wildcard(4));
34         return NULL;
35 }
36
37 static void *d(void *obj)
38 {
39         r3 = y.load(wildcard(5));
40         r4 = x.load(wildcard(6));
41         return NULL;
42 }
43
44
45 int user_main(int argc, char **argv)
46 {
47         pthread_t t1, t2, t3, t4;
48
49         atomic_init(&x, 0);
50         atomic_init(&y, 0);
51
52         printf("Main thread: creating 4 threads\n");
53         pthread_create(&t1,NULL, &a, NULL);
54         pthread_create(&t2,NULL, &b, NULL);
55         pthread_create(&t3,NULL, &c, NULL);
56         pthread_create(&t4,NULL, &d, NULL);
57
58         pthread_join(t1,NULL);
59         pthread_join(t2,NULL);
60         pthread_join(t3,NULL);
61         pthread_join(t4,NULL);
62         printf("Main thread is finished\n");
63
64         /*
65          * This condition should not be hit if the execution is SC */
66         bool sc = (r1 == 1 && r2 == 0 && r3 == 1 && r4 == 0);
67         //MODEL_ASSERT(!sc);
68
69         return 0;
70 }