Calling Disconnect while the read thread is running is racy because the
thread can also call Disconnect. This is a follow-up to
b424b0bf, which
reorders other occurences of Disconnect/StopReadThread I can find, and also
adds an assertion to guard against new occurences being introduced.
void Communication::Clear() {
SetReadThreadBytesReceivedCallback(nullptr, nullptr);
- Disconnect(nullptr);
StopReadThread(nullptr);
+ Disconnect(nullptr);
}
ConnectionStatus Communication::Connect(const char *url, Status *error_ptr) {
LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION),
"{0} Communication::Disconnect ()", this);
+ assert((!m_read_thread_enabled || m_read_thread_did_exit) &&
+ "Disconnecting while the read thread is running is racy!");
lldb::ConnectionSP connection_sp(m_connection_sp);
if (connection_sp) {
ConnectionStatus status = connection_sp->Disconnect(error_ptr);
DidDestroy();
StopPrivateStateThread();
}
- m_stdio_communication.Disconnect();
m_stdio_communication.StopReadThread();
+ m_stdio_communication.Disconnect();
m_stdin_forward = false;
if (m_process_input_reader) {