fd67b60ec7a02ebf39244821030f541699260737
[cdsspec-compiler.git] / benchmark / chase-lev-deque-bugfix / main.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
16 static void task(void * param) {
17         a=steal(q);
18         if (a == ABORT) {
19                 printf("Steal NULL\n");
20         } else {
21                 printf("Steal %d\n", a);
22         }
23         int x=steal(q);
24         if (x == ABORT) {
25                 printf("Steal NULL\n");
26         } else {
27                 printf("Steal %d\n", x);
28         }
29 }
30
31 int user_main(int argc, char **argv)
32 {
33         /**
34                 @Begin
35                 @Entry_point
36                 @End
37         */
38         thrd_t t;
39         q=create();
40         thrd_create(&t, task, 0);
41         push(q, 1);
42         printf("Push 1\n");
43         push(q, 2);
44         printf("Push 2\n");
45         push(q, 4);
46         printf("Push 4\n");
47         b=take(q);
48         if (b == EMPTY) {
49                 printf("Take NULL\n");
50         } else {
51                 printf("Take %d\n", b);
52         }
53         c=take(q);
54         if (c == EMPTY) {
55                 printf("Take NULL\n");
56         } else {
57                 printf("Take %d\n", c);
58         }
59         thrd_join(t);
60 /*
61         bool correct=true;
62         if (a!=1 && a!=2 && a!=4 && a!= EMPTY)
63                 correct=false;
64         if (b!=1 && b!=2 && b!=4 && b!= EMPTY)
65                 correct=false;
66         if (c!=1 && c!=2 && c!=4 && a!= EMPTY)
67                 correct=false;
68         if (a!=EMPTY && b!=EMPTY && c!=EMPTY && (a+b+c)!=7)
69                 correct=false;
70         if (!correct)
71                 printf("a=%d b=%d c=%d\n",a,b,c);
72                 */
73         //MODEL_ASSERT(correct);
74
75         return 0;
76 }