deque: fix bugs in assertion code and move up 3 variables...
authorBrian Demsky <bdemsky@uci.edu>
Thu, 7 Mar 2013 03:13:19 +0000 (19:13 -0800)
committerBrian Demsky <bdemsky@uci.edu>
Thu, 7 Mar 2013 03:13:19 +0000 (19:13 -0800)
chase-lev-deque/main.c

index ee69867f2ebb37d1aa1cd4d9c0bb9f19c0ef2926..0a29a51572551004ca40b3a8c28551e9e161c62d 100644 (file)
@@ -9,11 +9,10 @@
 Deque *q;
 int a;
 int b;
 Deque *q;
 int a;
 int b;
+int c;
 
 static void task(void * param) {
 
 static void task(void * param) {
-       do {
-               a=steal(q);
-       } while(a==EMPTY);
+       a=steal(q);
 }
 
 int user_main(int argc, char **argv)
 }
 
 int user_main(int argc, char **argv)
@@ -23,9 +22,20 @@ int user_main(int argc, char **argv)
        thrd_create(&t, task, 0);
        push(q, 1);
        push(q, 2);
        thrd_create(&t, task, 0);
        push(q, 1);
        push(q, 2);
+       push(q, 4);
        b=take(q);
        b=take(q);
+       c=take(q);
        thrd_join(t);
        thrd_join(t);
-       if (a+b!=3)
-               printf("a=%d b=%d\n",a,b);
+       bool correct=true;
+       if (a!=1 && a!=2 && a!=4 && a!= EMPTY)
+               correct=false;
+       if (b!=1 && b!=2 && b!=4 && b!= EMPTY)
+               correct=false;
+       if (c!=1 && c!=2 && c!=4 && a!= EMPTY)
+               correct=false;
+       if (a!=EMPTY && b!=EMPTY && c!=EMPTY && (a+b+c)!=7)
+               correct=false;
+       if (!correct)
+               printf("a=%d b=%d c=%d\n",a,b,c);
        return 0;
 }
        return 0;
 }