From: Vadim Zeitlin Date: Mon, 22 Mar 1999 12:49:05 +0000 (+0000) Subject: attempt to fix Delete/Pause deadlock X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/862cc6f9cd505cc5ac1b568bf72f1736a6cf8379 attempt to fix Delete/Pause deadlock git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1951 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/unix/threadpsx.cpp b/src/unix/threadpsx.cpp index 5c3382cdc7..b5cdd32588 100644 --- a/src/unix/threadpsx.cpp +++ b/src/unix/threadpsx.cpp @@ -257,7 +257,7 @@ private: // this (mutex, cond) pair is used to synchronize the main thread and this // thread in several situations: // 1. The thread function blocks until condition is signaled by Run() when - // it's initially created - this allows create thread in "suspended" + // it's initially created - this allows thread creation in "suspended" // state // 2. The Delete() function blocks until the condition is signaled when the // thread exits. @@ -279,9 +279,10 @@ void *wxThreadInternal::PthreadStart(void *ptr) wxThread *thread = (wxThread *)ptr; wxThreadInternal *pthread = thread->p_internal; - if ( pthread_setspecific(gs_keySelf, thread) != 0 ) + int rc = pthread_setspecific(gs_keySelf, thread); + if ( rc != 0 ) { - wxLogError(_("Can not start thread: error writing TLS.")); + wxLogSysError(rc, _("Can not start thread: error writing TLS.")); return (void *)-1; } @@ -387,6 +388,12 @@ void wxThreadInternal::Pause() wxCHECK_RET( m_state == STATE_PAUSED, "thread must first be paused with wxThread::Pause()." ); + // don't pause the thread which is being terminated - this would lead to + // deadlock if the thread is paused after Delete() had called Resume() but + // before it had time to call Cancel() + if ( m_cancelled ) + return; + // wait until the condition is signaled from Resume() m_condSuspend.Wait(m_mutexSuspend); }