From 22a24446c1f3c0323f1f0155d964d4484a37dbb3 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 26 Nov 2020 16:30:17 +0300 Subject: [PATCH] Threads: fix minor race Has already been in "fixed" state in past... --- Utilities/Thread.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index a6f5e1df68..64b5e73a88 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -2010,7 +2010,10 @@ u64 thread_base::finalize(thread_state result_state) noexcept atomic_wait_engine::set_wait_callback(nullptr); - // Return true if need to delete thread object (no) + // Avoid race with the destructor + const u64 _self = m_thread; + + // Set result state (errored or finalized) const bool ok = 0 == (3 & ~m_sync.fetch_op([&](u64& v) { v &= -4; @@ -2020,8 +2023,7 @@ u64 thread_base::finalize(thread_state result_state) noexcept // Signal waiting threads m_sync.notify_all(2); - // No detached thread supported atm - return m_thread; + return _self; } thread_base::native_entry thread_base::finalize(u64 _self) noexcept