Revision: 33608
http://sourceforge.net/p/opalvoip/code/33608
Author: rjongbloed
Date: 2015-05-19 05:09:16 +0000 (Tue, 19 May 2015)
Log Message:
-----------
Do not use pthread_kill() with SIGKILL, kills the whole process. Correct mechanism for forceful termination of a thread is pthread_cancel() with pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS).
Modified Paths:
--------------
ptlib/trunk/src/ptlib/unix/tlibthrd.cxx
Modified: ptlib/trunk/src/ptlib/unix/tlibthrd.cxx
===================================================================
--- ptlib/trunk/src/ptlib/unix/tlibthrd.cxx 2015-05-18 04:05:31 UTC (rev 33607)
+++ ptlib/trunk/src/ptlib/unix/tlibthrd.cxx 2015-05-19 05:09:16 UTC (rev 33608)
@@ -356,6 +356,9 @@
#if P_USE_THREAD_CANCEL
// make sure the cleanup routine is called when the threade cancelled
pthread_cleanup_push(&PThread::PX_ThreadEnd, arg);
+ // Allow cancel to happen any time
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
#endif
thread->PX_ThreadBegin();
@@ -761,7 +764,7 @@
PTRACE(2, "PTLib\tForcing termination of thread id=0x" << hex << m_threadId << dec);
PXAbortBlock();
- if (WaitForTermination(20))
+ if (WaitForTermination(100))
return;
#ifndef P_HAS_SEMAPHORES
@@ -778,12 +781,10 @@
if (m_threadId != PNullThreadIdentifier) {
#if P_USE_THREAD_CANCEL
pthread_cancel(m_threadId);
- if (WaitForTermination(20))
- return;
- // get more forceful
+#else
+ pthread_kill(m_threadId, SIGKILL);
#endif
-
- pthread_kill(m_threadId, SIGKILL);
+ WaitForTermination(100);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|