[Lldb-commits] [lldb] r123309 - /lldb/trunk/source/Core/Communication.cpp

Stephen Wilson wilsons at start.ca
Tue Jan 11 20:22:54 PST 2011


Author: wilsons
Date: Tue Jan 11 22:22:54 2011
New Revision: 123309

URL: http://llvm.org/viewvc/llvm-project?rev=123309&view=rev
Log:
Do not pass an invalid thread to Thread{Cancel,Join}.

A race condition exists between StopReadThread and the reader thread proper.
When StopReadThread sets m_read_thread_enabled to false the reader thread can
terminate and set m_read_thread to LLDB_INVALID_HOST_THREAD on exit.  Thus calls
to ThreadCancel or ThreadJoin in StopReadThread can be passed an invalid handle.

This patch removes the race by using m_read_thread_enabled as the flag thru
which the reader thread can notify the parent thread of early/abnormal
termination.


Modified:
    lldb/trunk/source/Core/Communication.cpp

Modified: lldb/trunk/source/Core/Communication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Communication.cpp?rev=123309&r1=123308&r2=123309&view=diff
==============================================================================
--- lldb/trunk/source/Core/Communication.cpp (original)
+++ lldb/trunk/source/Core/Communication.cpp Tue Jan 11 22:22:54 2011
@@ -138,7 +138,7 @@
                                          timeout_usec, 
                                          m_connection_sp.get());
 
-    if (m_read_thread != LLDB_INVALID_HOST_THREAD)
+    if (m_read_thread_enabled)
     {
         // We have a dedicated read thread that is getting data for us
         size_t cached_bytes = GetCachedBytes (dst, dst_len);
@@ -257,8 +257,9 @@
 
     Host::ThreadCancel (m_read_thread, error_ptr);
 
-    return Host::ThreadJoin (m_read_thread, NULL, error_ptr);
+    bool status = Host::ThreadJoin (m_read_thread, NULL, error_ptr);
     m_read_thread = LLDB_INVALID_HOST_THREAD;
+    return status;
 }
 
 
@@ -317,7 +318,7 @@
 bool
 Communication::ReadThreadIsRunning ()
 {
-    return m_read_thread != LLDB_INVALID_HOST_THREAD;
+    return m_read_thread_enabled;
 }
 
 void *
@@ -370,7 +371,7 @@
 
     // Let clients know that this thread is exiting
     comm->BroadcastEvent (eBroadcastBitReadThreadDidExit);
-    comm->m_read_thread = LLDB_INVALID_HOST_THREAD;
+    comm->m_read_thread_enabled = false;
     comm->Disconnect();
     return NULL;
 }





More information about the lldb-commits mailing list