need to fix deque
[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         // FIXME: Add the following take() will expose an Uninitialzied Load bug...
18         //a=take(q);
19
20         a=steal(q);
21 }
22
23 int user_main(int argc, char **argv)
24 {
25         /**
26                 @Begin
27                 @Entry_point
28                 @End
29         */
30         thrd_t t;
31         q=create();
32         thrd_create(&t, task, 0);
33         push(q, 1);
34         push(q, 2);
35         push(q, 4);
36         b=take(q);
37         c=take(q);
38         thrd_join(t);
39
40         bool correct=true;
41         if (a!=1 && a!=2 && a!=4 && a!= EMPTY)
42                 correct=false;
43         if (b!=1 && b!=2 && b!=4 && b!= EMPTY)
44                 correct=false;
45         if (c!=1 && c!=2 && c!=4 && a!= EMPTY)
46                 correct=false;
47         if (a!=EMPTY && b!=EMPTY && c!=EMPTY && (a+b+c)!=7)
48                 correct=false;
49         if (!correct)
50                 printf("a=%d b=%d c=%d\n",a,b,c);
51         MODEL_ASSERT(correct);
52
53         return 0;
54 }