Revision: 21345
http://opalvoip.svn.sourceforge.net/opalvoip/?rev=21345&view=rev
Author: hfriederich
Date: 2008-10-15 22:18:46 +0000 (Wed, 15 Oct 2008)
Log Message:
-----------
Fix another deadlock occurring when calling PTRACE while
process.activeThreads is locked
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-15 11:46:05 UTC (rev 21344)
+++ ptlib/trunk/src/ptlib/unix/tlibthrd.cxx 2008-10-15 22:18:46 UTC (rev 21345)
@@ -127,11 +127,23 @@
process.breakBlock.Wait(delay);
process.activeThreadMutex.Wait();
- for (PINDEX i = 0; i < process.activeThreads.GetSize(); ++i) {
- PThread & thread = process.activeThreads.GetDataAt(i);
- if (thread.autoDelete && thread.IsTerminated())
- delete process.activeThreads.RemoveAt(process.activeThreads.GetKeyAt(i));
- }
+ PBoolean found;
+ do {
+ found = PFalse;
+ for (PINDEX i = 0; i < process.activeThreads.GetSize(); ++i) {
+ PThread & thread = process.activeThreads.GetDataAt(i);
+ if (thread.autoDelete && thread.IsTerminated()) {
+ // unlock the activeThreadMutex to avoid deadlocks:
+ // if somewhere in the destructor a call to PTRACE() is made,
+ // which itself calls PThread::Current(), deadlocks are possible
+ process.activeThreadMutex.Signal();
+ delete process.activeThreads.RemoveAt(process.activeThreads.GetKeyAt(i));
+ process.activeThreadMutex.Wait();
+ found = PTrue;
+ break;
+ }
+ }
+ } while (found == PTrue);
process.activeThreadMutex.Signal();
process.PXCheckSignals();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|