Merge branch 'master' of /home/git/concurrency-benchmarks
[c11concurrency-benchmarks.git] / cdschecker_modified_benchmarks / chase-lev-deque / main.cc
1 #include <stdlib.h>
2 #include <assert.h>
3 #include <stdio.h>
4 #include "cds_threads.h"
5 //#include <atomic>
6
7 #include "model-assert.h"
8
9 #include "deque.h"
10
11 #define ITERATION 1
12
13 Deque *q;
14 int a;
15 int b;
16 int c;
17
18 static void task(void * param) {
19         for (int i = 0; i < ITERATION; i++)
20                 a=steal(q);
21 }
22
23 int user_main(int argc, char **argv)
24 {
25         q=create();
26         std::thread t(task, (void *)0);
27
28         for (int i = 0; i < ITERATION; i++) {
29                 push(q, 1);
30                 push(q, 2);
31                 push(q, 4);
32                 b=take(q);
33                 c=take(q);
34         }
35
36         t.join();
37
38         bool correct=true;
39         if (a!=1 && a!=2 && a!=4 && a!= EMPTY)
40                 correct=false;
41         if (b!=1 && b!=2 && b!=4 && b!= EMPTY)
42                 correct=false;
43         if (c!=1 && c!=2 && c!=4 && a!= EMPTY)
44                 correct=false;
45         if (a!=EMPTY && b!=EMPTY && c!=EMPTY && (a+b+c)!=7)
46                 correct=false;
47         if (!correct)
48                 printf("a=%d b=%d c=%d\n",a,b,c);
49         MODEL_ASSERT(correct);
50
51         return 0;
52 }