]> git.kaiwu.me - klib.git/commitdiff
fixed a dead loop when n_threads==1
authorHeng Li <lh3@me.com>
Wed, 9 Oct 2013 16:51:34 +0000 (12:51 -0400)
committerHeng Li <lh3@me.com>
Wed, 9 Oct 2013 16:51:34 +0000 (12:51 -0400)
kthread.c

index 8260db05555930520bbd11be020ee2404cc1eaa5..0833cfdaa5a65fa6905b6c33a21e75ac3116ca90 100644 (file)
--- a/kthread.c
+++ b/kthread.c
@@ -87,7 +87,7 @@ static inline int steal_work(kt_for_t *f) // steal work from the worker with the
        for (i = 0; i < f->n; ++i)
                if (max < dq_size(f->w[i].q)) // max is not accurate as other workers may steal from the same queue, but it does not matter.
                        max = dq_size(f->w[i].q), max_i = i;
-       if (dq_deq(f->w[max_i].q, 0, &k) < 0) k = -1;
+       if (max_i < 0 || dq_deq(f->w[max_i].q, 0, &k) < 0) k = -1;
        return k;
 }