diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-26 23:41:54 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-26 23:42:28 -0800 |
| commit | 0867d597788099c213b1f3b0bbd2f3adbaeceee2 (patch) | |
| tree | b86b0a14b34687cda30e5e93c941846aa6cd57f3 /src/core | |
| parent | 93d72cab018ddbdb35a03e450b5725a2a7e58eb6 (diff) | |
| download | nng-0867d597788099c213b1f3b0bbd2f3adbaeceee2.tar.gz nng-0867d597788099c213b1f3b0bbd2f3adbaeceee2.tar.bz2 nng-0867d597788099c213b1f3b0bbd2f3adbaeceee2.zip | |
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.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/thread.c | 6 |
1 files changed, 3 insertions, 3 deletions
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); |
