[Lldb-commits] [PATCH] D19122: LLDB: Fixed race condition on timeout when stopping private state thread

Cameron via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 14 16:18:01 PDT 2016

cameron314 added a comment.

OK, I'll pare down the patch to just that line then.

I found the reason for the time out. At the end of our debug session, we destroy the Target, which destroys the process. Process::Destroy in turn calls Process::Detach, which calls DoDetach just before calling StopPrivateStateThread (which times out). Our platform's process object (modeled after the GDB remote one) sets the thread state to eStateDetached in its DoDetach implementation; and the private state thread exits as soon as it sees that state, meaning it's no longer around handle the eBroadcastInternalStateControlStop state event from the StopPrivateStateThread just after.

I think the real bug is in StopPrivateStateThread, which only sends the stop state if the thread is still joinable; since I removed the Reset, it is of course still joinable after it exits. But even with the Reset (which we agree shouldn't be there), there is still a race between the time the detach signal is sent and when the thread sees it and exits. It seems once a detach or stop is sent, no further detaches/stops can be sent, regardless of what the thread is doing (since it will exit as soon as it sees the first one). So there should be a flag to that effect somewhere checked in ControlPrivateStateThread. Probably all the calls to `IsJoinable()` should be replaced with calls to `PrivateStateThreadIsValid`, which should be updated to check that flag.

I don't see a nice way to add this flag for each private state thread, though, instead of for the process object as a whole. But maybe that's all that's necessary?



More information about the lldb-commits mailing list