DavidSpickett wrote:

Tried to unpick the layers here. HostThread contains a HostNativeThreadBase. 
HostThread's Reset is:
```
void HostThread::Reset() { return m_native_thread->Reset(); }
```
Which has a default implementation of:
```
void HostNativeThreadBase::Reset() {
  m_thread = LLDB_INVALID_HOST_THREAD;
  m_result = 0; // NOLINT(modernize-use-nullptr)
}
```
Windows overrides this to:
```
void HostThreadWindows::Reset() {
  if (m_owns_handle && m_thread != LLDB_INVALID_HOST_THREAD)
    ::CloseHandle(m_thread);

  HostNativeThreadBase::Reset();
}
```
Which we would expect. We no longer need the thread so close the handle.

HostThreadPosix does not override this method, but it does have its own Detach, 
which does pthread_detach, then calls Reset():
```
Status HostThreadPosix::Detach() {
  Status error;
  if (IsJoinable()) {
    int err = ::pthread_detach(m_thread);
    error = Status(err, eErrorTypePOSIX);
  }
  Reset();
  return error;
}
```
This method is not called by anything in a Linux build. Code looks sensible 
though.

So I wonder if we should be calling pthread_detach in HostThreadPosix::Reset, 
then removing the unused Detatch. Then we could call Reset on the HostThread in 
lldb/source/Host/common/MonitoringProcessLauncher.cpp without needing to get 
the native thread:
```
  if (process.GetProcessId() != LLDB_INVALID_PROCESS_ID) {
    Log *log = GetLog(LLDBLog::Process);

    assert(launch_info.GetMonitorProcessCallback());
    llvm::Expected<HostThread> maybe_thread =
        process.StartMonitoring(launch_info.GetMonitorProcessCallback());
<...>
```

https://github.com/llvm/llvm-project/pull/177572
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to