[Lldb-commits] [lldb] Fix single thread stepping timeout race condition (PR #104195)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Aug 14 12:22:20 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: None (jeffreytan81)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/104195.diff
1 Files Affected:
- (modified) lldb/source/Target/ThreadPlanSingleThreadTimeout.cpp (+2-2)
``````````diff
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() {
``````````
</details>
https://github.com/llvm/llvm-project/pull/104195
More information about the lldb-commits
mailing list