From: Heng Li Date: Wed, 9 Oct 2013 16:51:34 +0000 (-0400) Subject: fixed a dead loop when n_threads==1 X-Git-Tag: spawn-final~4 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=326cf675b2d32b99c37a12acd45d116ee202cea8;p=klib.git fixed a dead loop when n_threads==1 --- diff --git a/kthread.c b/kthread.c index 8260db0..0833cfd 100644 --- 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; }