[Lldb-commits] [PATCH] Fix deadlock in operation thread in NativeProcessLinux
Tamas Berghammer
tberghammer at google.com
Tue Mar 3 05:25:48 PST 2015
Update based on suggestion in comment
http://reviews.llvm.org/D8030
Files:
source/Plugins/Process/Linux/NativeProcessLinux.cpp
Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp
===================================================================
--- source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -142,6 +142,8 @@
using namespace lldb;
using namespace lldb_private;
+ static void * const EXIT_OPERATION = nullptr;
+
const UnixSignals&
GetUnixSignals ()
{
@@ -3370,14 +3372,11 @@
assert(false && "Unexpected errno from sem_wait");
}
- // nullptr as operation means the operation thread should exit. Cancel() can't be used
- // because it is not supported on android.
- if (!monitor->m_operation)
- {
- // notify calling thread that operation is complete
- sem_post(&monitor->m_operation_done);
+ // EXIT_OPERATION used to stop the operation thread because Cancel() isn't supported on
+ // android. We don't have to send a post to the m_operation_done semaphore because in this
+ // case the synchronization is achieved by a Join() call
+ if (monitor->m_operation == EXIT_OPERATION)
break;
- }
reinterpret_cast<Operation*>(monitor->m_operation)->Execute(monitor);
@@ -3396,12 +3395,17 @@
// notify operation thread that an operation is ready to be processed
sem_post(&m_operation_pending);
- // wait for operation to complete
- while (sem_wait(&m_operation_done))
+ // Don't wait for the operation to complete in case of an exit operation. The operation thread
+ // will exit without posting to the semaphore
+ if (m_operation != EXIT_OPERATION)
{
- if (errno == EINTR)
- continue;
- assert(false && "Unexpected errno from sem_wait");
+ // wait for operation to complete
+ while (sem_wait(&m_operation_done))
+ {
+ if (errno == EINTR)
+ continue;
+ assert(false && "Unexpected errno from sem_wait");
+ }
}
}
@@ -3564,9 +3568,9 @@
void
NativeProcessLinux::StopMonitor()
{
- StopOpThread();
StopMonitoringChildProcess();
StopCoordinatorThread ();
+ StopOpThread();
sem_destroy(&m_operation_pending);
sem_destroy(&m_operation_done);
@@ -3583,7 +3587,7 @@
if (!m_operation_thread.IsJoinable())
return;
- DoOperation(nullptr); // nullptr as operation ask the operation thread to exit
+ DoOperation(EXIT_OPERATION);
m_operation_thread.Join(nullptr);
}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8030.21098.patch
Type: text/x-patch
Size: 2545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150303/f1d174a5/attachment.bin>
More information about the lldb-commits
mailing list