5c88a76e9c413069b80d76be51372fc73b964caf
[cdsspec-compiler.git] / benchmark / chase-lev-deque-bugfix / testcase2.c
1 #include <stdlib.h>
2 #include <assert.h>
3 #include <stdio.h>
4 #include <threads.h>
5 #include <stdatomic.h>
6
7 #include "model-assert.h"
8
9 #include "deque.h"
10
11 Deque *q;
12 int a;
13 int b;
14 int c;
15 int x;
16
17 static void task(void * param) {
18         a=steal(q);
19         if (a == ABORT) {
20                 printf("Steal NULL\n");
21         } else {
22                 printf("Steal %d\n", a);
23         }
24         /*
25         x=steal(q);
26         if (x == ABORT) {
27                 printf("Steal NULL\n");
28         } else {
29                 printf("Steal %d\n", x);
30         }
31         */
32 }
33
34 int user_main(int argc, char **argv)
35 {
36         /**
37                 @Begin
38                 @Entry_point
39                 @End
40         */
41         thrd_t t;
42         q=create();
43         push(q, 1);
44         printf("Push 1\n");
45         push(q, 2);
46         printf("Push 2\n");
47         push(q, 4);
48         printf("Push 4\n");
49         push(q, 5);
50         printf("Push 5\n");
51         thrd_create(&t, task, 0);
52
53         b=take(q);
54         if (b == EMPTY) {
55                 printf("Take NULL\n");
56         } else {
57                 printf("Take %d\n", b);
58         }
59         c=take(q);
60         if (c == EMPTY) {
61                 printf("Take NULL\n");
62         } else {
63                 printf("Take %d\n", c);
64         }
65         thrd_join(t);
66 /*
67         bool correct=true;
68         if (a!=1 && a!=2 && a!=4 && a!= EMPTY)
69                 correct=false;
70         if (b!=1 && b!=2 && b!=4 && b!= EMPTY)
71                 correct=false;
72         if (c!=1 && c!=2 && c!=4 && a!= EMPTY)
73                 correct=false;
74         if (a!=EMPTY && b!=EMPTY && c!=EMPTY && (a+b+c)!=7)
75                 correct=false;
76         if (!correct)
77                 printf("a=%d b=%d c=%d\n",a,b,c);
78                 */
79         //MODEL_ASSERT(correct);
80
81         return 0;
82 }