Revision: 21271
http://opalvoip.svn.sourceforge.net/opalvoip/?rev=21271&view=rev
Author: hfriederich
Date: 2008-10-08 16:53:38 +0000 (Wed, 08 Oct 2008)
Log Message:
-----------
Fix deadlock within PTRACE()
Modified Paths:
--------------
ptlib/trunk/src/ptlib/unix/tlibthrd.cxx
Modified: ptlib/trunk/src/ptlib/unix/tlibthrd.cxx
===================================================================
--- ptlib/trunk/src/ptlib/unix/tlibthrd.cxx 2008-10-08 05:37:41 UTC (rev 21270)
+++ ptlib/trunk/src/ptlib/unix/tlibthrd.cxx 2008-10-08 16:53:38 UTC (rev 21271)
@@ -826,6 +826,13 @@
PThread * thread = (PThread *)arg;
PProcess & process = PProcess::Current();
process.OnThreadEnded(*thread);
+
+ // Calls to PTRACE() MUST be made with activeThreadMutex unlocked, or deadlocks may occur.
+ // (PTRACE() itself calls PThread::Current()). Also, PTRACE must be done BEFORE removing the
+ // thread from the activeThreads dictionary, or PTrace::Current() will create a new
+ // PExternalThread instance, causing the very same deadlock
+ PTRACE(5, "PWLib\tEnded thread " << thread << ' ' << thread->GetThreadName());
+
process.activeThreadMutex.Wait();
pthread_t id = thread->GetThreadId();
@@ -835,10 +842,8 @@
process.activeThreadMutex.Signal();
PTRACE(2, "PWLib\tAttempted to multiply end thread " << thread << " ThreadID=" << (void *)id);
return;
- }
+ }
- PTRACE(5, "PWLib\tEnded thread " << thread << ' ' << thread->GetThreadName());
-
// remove this thread from the active thread list
process.activeThreads.SetAt((unsigned)id, NULL);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|