a67be6efad20e8f81fdf029c1ffe13e8e363a29c
[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 task1(void * param) {
17         a=steal(q);
18 }
19
20 static void task2(void * param) {
21         a=take(q);
22 }
23
24 int user_main(int argc, char **argv)
25 {
26         /**
27                 @Begin
28                 @Entry_point
29                 @End
30         */
31         thrd_t t1, t2;
32         q=create();
33         push(q, 1);
34         push(q, 2);
35         thrd_create(&t1, task1, 0);
36         thrd_create(&t2, task2, 0);
37         push(q, 4);
38         b=take(q);
39         c=take(q);
40         thrd_join(t1);
41         thrd_join(t2);
42
43         bool correct=true;
44         if (a!=1 && a!=2 && a!=4 && a!= EMPTY)
45                 correct=false;
46         if (b!=1 && b!=2 && b!=4 && b!= EMPTY)
47                 correct=false;
48         if (c!=1 && c!=2 && c!=4 && a!= EMPTY)
49                 correct=false;
50         if (a!=EMPTY && b!=EMPTY && c!=EMPTY && (a+b+c)!=7)
51                 correct=false;
52         if (!correct)
53                 printf("a=%d b=%d c=%d\n",a,b,c);
54         //MODEL_ASSERT(correct);
55
56         return 0;
57 }