Skip to content

Commit 54154f9

Browse files
jeffreytan81jeffreytan81
andauthored
Fix single thread stepping timeout race condition (#104195)
This PR fixes a potential race condition in #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 <[email protected]>
1 parent e61776a commit 54154f9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lldb/source/Target/ThreadPlanSingleThreadTimeout.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ ThreadPlanSingleThreadTimeout::ThreadPlanSingleThreadTimeout(
2929
: ThreadPlan(ThreadPlan::eKindSingleThreadTimeout, "Single thread timeout",
3030
thread, eVoteNo, eVoteNoOpinion),
3131
m_info(info), m_state(State::WaitTimeout) {
32-
// TODO: reuse m_timer_thread without recreation.
33-
m_timer_thread = std::thread(TimeoutThreadFunc, this);
3432
m_info->m_isAlive = true;
3533
m_state = m_info->m_last_state;
34+
// TODO: reuse m_timer_thread without recreation.
35+
m_timer_thread = std::thread(TimeoutThreadFunc, this);
3636
}
3737

3838
ThreadPlanSingleThreadTimeout::~ThreadPlanSingleThreadTimeout() {

0 commit comments

Comments
 (0)