diff --git a/Utilities/Thread.h b/Utilities/Thread.h index bafcea0b9f..66ccfa9fb2 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -797,31 +797,30 @@ public: m_count = 0; // Create all threads - for (u32 i = 0; i < count - 1; i++) + for (; m_count < count - 1; m_count++) { // Copy the context std::remove_cvref_t context(static_cast(f)); // Perform the check and additional preparations for each context - if (!std::invoke(std::forward(check), i, context)) + if (!std::invoke(std::forward(check), m_count, context)) { return; } - m_count++; - new (static_cast(m_threads + i)) Thread(std::string(name) + std::to_string(i + 1), std::move(context)); + new (static_cast(m_threads + m_count)) Thread(std::string(name) + std::to_string(m_count + 1), std::move(context)); } // Move the context (if movable) std::remove_cvref_t context(std::forward(f)); - if (!std::invoke(std::forward(check), m_count - 1, context)) + if (!std::invoke(std::forward(check), m_count, context)) { return; } + new (static_cast(m_threads + m_count)) Thread(std::string(name) + std::to_string(m_count + 1), std::move(context)); m_count++; - new (static_cast(m_threads + m_count - 1)) Thread(std::string(name) + std::to_string(m_count - 1), std::move(context)); } // Default constructor