From 0867d597788099c213b1f3b0bbd2f3adbaeceee2 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 26 Jan 2017 23:41:54 -0800 Subject: Fix bug that prevents threads from starting if waited on too soon. This is partly caused by a race, but also an incorrect boolean short-circuit that I had not reasoned about properly. Mostly changing the boolean order fixes the condition, so that we prefer to start than to stop, if both are set. --- src/core/thread.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/thread.c b/src/core/thread.c index 74a434f9..bccb4ff3 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -86,14 +86,14 @@ static void nni_thr_wrap(void *arg) { nni_thr *thr = arg; - int stop; + int start; nni_plat_mtx_lock(&thr->mtx); - while (((stop = thr->stop) == 0) && (thr->start == 0)) { + while (((start = thr->start) == 0) && (thr->stop == 0)) { nni_plat_cv_wait(&thr->cv); } nni_plat_mtx_unlock(&thr->mtx); - if ((!stop) && (thr->fn != NULL)) { + if ((start) && (thr->fn != NULL)) { thr->fn(thr->arg); } nni_plat_mtx_lock(&thr->mtx); -- cgit v1.2.3-70-g09d2