diff --git a/core/teca_cpu_thread_pool.h b/core/teca_cpu_thread_pool.h index 14b0e7523..d4daa603c 100644 --- a/core/teca_cpu_thread_pool.h +++ b/core/teca_cpu_thread_pool.h @@ -229,9 +229,12 @@ int teca_cpu_thread_pool::wait_some(long n_to_wait, } } - // if we have not accumulated the requested number of datasets + // we have the requested number of datasets + if (data.size() >= static_cast(n_to_wait)) + break; + // wait for the user supplied duration before re-scanning - if (thread_valid && (data.size() < static_cast(n_to_wait))) + if (thread_valid) std::this_thread::sleep_for(std::chrono::nanoseconds(poll_interval)); } diff --git a/core/teca_cuda_thread_pool.h b/core/teca_cuda_thread_pool.h index 874526e1d..618454291 100644 --- a/core/teca_cuda_thread_pool.h +++ b/core/teca_cuda_thread_pool.h @@ -235,7 +235,7 @@ int teca_cuda_thread_pool::wait_some(long n_to_wait, // gather the requested number of datasets size_t thread_valid = 1; - while (thread_valid) + while (thread_valid && ((data.size() < static_cast(n_to_wait)))) { { thread_valid = 0; @@ -259,9 +259,12 @@ int teca_cuda_thread_pool::wait_some(long n_to_wait, } } - // if we have not accumulated the requested number of datasets + // we have the requested number of datasets + if (data.size() >= static_cast(n_to_wait)) + break; + // wait for the user supplied duration before re-scanning - if (thread_valid && (data.size() < static_cast(n_to_wait))) + if (thread_valid) std::this_thread::sleep_for(std::chrono::nanoseconds(poll_interval)); }