From 2c35d5fa1c969215034d771d90e6743cfb509eb6 Mon Sep 17 00:00:00 2001 From: Gammasoft Date: Sun, 13 Aug 2023 21:54:47 +0200 Subject: [PATCH] Fix wait_any with timeout infinite method --- src/xtd.core/src/xtd/threading/wait_handle.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/xtd.core/src/xtd/threading/wait_handle.cpp b/src/xtd.core/src/xtd/threading/wait_handle.cpp index a0fac6775ba0..0f3196275b01 100644 --- a/src/xtd.core/src/xtd/threading/wait_handle.cpp +++ b/src/xtd.core/src/xtd/threading/wait_handle.cpp @@ -193,13 +193,13 @@ size_t wait_handle::wait_any(const std::vector& wait_handles, int3 if (milliseconds_timeout < timeout::infinite) throw argument_exception(csf_); if (milliseconds_timeout == timeout::infinite) { - for (auto index = 0ul; index < wait_handles.size(); ++index) { - if (wait_handles[index]->wait_one(0) == true) - return index; - thread::yield(); - thread::sleep(1); - } - return wait_timeout; + do { + for (auto index = 0ul; index < wait_handles.size(); ++index) { + if (wait_handles[index]->wait_one(0) == true) return index; + thread::yield(); + thread::sleep(1); + } + } while (true); } int32 timeout = milliseconds_timeout; @@ -213,5 +213,6 @@ size_t wait_handle::wait_any(const std::vector& wait_handles, int3 thread::sleep(1); } } while (timeout >= 0); + return wait_timeout; }