From 485651138e96741ff79f16d212f4db0fa7ec1b28 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 19 Nov 2015 10:26:37 +0100 Subject: executor: fix detection of out of threads --- executor/executor.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'executor/executor.cc') diff --git a/executor/executor.cc b/executor/executor.cc index 671828703..fa03107bd 100644 --- a/executor/executor.cc +++ b/executor/executor.cc @@ -335,21 +335,22 @@ thread_t* schedule_call(int n, int call_index, int call_num, uint64_t num_args, root = true; } // Find a spare thread to execute the call. - thread_t* th = 0; - for (int i = 0; i < kMaxThreads; i++) { - th = &threads[i]; + int i; + for (i = 0; i < kMaxThreads; i++) { + thread_t* th = &threads[i]; if (!th->created) thread_create(th, i, false); - if (flag_drop_privs && root != th->root) - continue; if (__atomic_load_n(&th->done, __ATOMIC_ACQUIRE)) { if (!th->handled) handle_completion(th); + if (flag_drop_privs && root != th->root) + continue; break; } } - if (th == &threads[kMaxThreads]) - fail("out of threads"); + if (i == kMaxThreads) + exitf("out of threads"); + thread_t* th = &threads[i]; debug("scheduling call %d [%s] on thread %d\n", call_index, syscalls[call_num].name, th->id); if (th->ready || !th->done || !th->handled) fail("bad thread state in schedule: ready=%d done=%d handled=%d", th->ready, th->done, th->handled); -- cgit mrf-deployment