Author: jeffreytan81 Date: 2024-08-15T09:57:01-07:00 New Revision: 54154f9f06e08b7ab3c7294352601ca4c6e5e160
URL: https://github.com/llvm/llvm-project/commit/54154f9f06e08b7ab3c7294352601ca4c6e5e160 DIFF: https://github.com/llvm/llvm-project/commit/54154f9f06e08b7ab3c7294352601ca4c6e5e160.diff LOG: Fix single thread stepping timeout race condition (#104195) This PR fixes a potential race condition in https://github.com/llvm/llvm-project/pull/90930. This race can happen because the original code set `m_info->m_isAlive = true` **after** the timer thread is created. So if there is a context switch happens and timer thread checks `m_info->m_isAlive` before main thread got a chance to run `m_info->m_isAlive = true`, the timer thread may treat `ThreadPlanSingleThreadTimeout` as not alive and simply exit resulting in async interrupt never being sent to resume all threads (deadlock). The PR fixes the race by initializing all states **before** worker timer thread creates. Co-authored-by: jeffreytan81 <jeffrey...@fb.com> Added: Modified: lldb/source/Target/ThreadPlanSingleThreadTimeout.cpp Removed: ################################################################################ diff --git a/lldb/source/Target/ThreadPlanSingleThreadTimeout.cpp b/lldb/source/Target/ThreadPlanSingleThreadTimeout.cpp index 0a939d55f4ce49..806ba95c508b7c 100644 --- a/lldb/source/Target/ThreadPlanSingleThreadTimeout.cpp +++ b/lldb/source/Target/ThreadPlanSingleThreadTimeout.cpp @@ -29,10 +29,10 @@ ThreadPlanSingleThreadTimeout::ThreadPlanSingleThreadTimeout( : ThreadPlan(ThreadPlan::eKindSingleThreadTimeout, "Single thread timeout", thread, eVoteNo, eVoteNoOpinion), m_info(info), m_state(State::WaitTimeout) { - // TODO: reuse m_timer_thread without recreation. - m_timer_thread = std::thread(TimeoutThreadFunc, this); m_info->m_isAlive = true; m_state = m_info->m_last_state; + // TODO: reuse m_timer_thread without recreation. + m_timer_thread = std::thread(TimeoutThreadFunc, this); } ThreadPlanSingleThreadTimeout::~ThreadPlanSingleThreadTimeout() { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits