summaryrefslogtreecommitdiff
path: root/sal/osl
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-08-06 18:09:49 +0200
committerMichael Stahl <mstahl@redhat.com>2015-08-06 19:40:10 +0200
commit8dc2f2f182e72e9fce277d8f5e9bcf3ce474f84f (patch)
tree3210e720565efb8e442a973f5e9df6089dc85693 /sal/osl
parentb02f792f23e6d5872de1f2f5abd0151a89751c43 (diff)
sal: fix assert in osl_joinWithThread()
e3a74864a02d2ed362f7bfb82c5ce6068b908101 was subtly wrong: in a --enable-online-update build, the assertion triggered with nonsensical stacks like: 4 in osl_joinWithThread(oslThread) at /sal/osl/unx/thread.cxx:441 5 in osl::Thread::join() at /include/osl/thread.hxx:111 6 in (anonymous namespace)::UpdateCheckJob::notifyTermination(com::sun::star::lang::EventObject const&) at /extensions/source/update/check/updatecheckjob.cxx:312 7 in framework::Desktop::impl_sendNotifyTerminationEvent() at /framework/source/services/desktop.cxx:1665 8 in framework::Desktop::terminate() at /framework/source/services/desktop.cxx:307 ... 14 in binaryurp::(anonymous namespace)::request(void*) at /binaryurp/source/reader.cxx:85 15 in cppu_threadpool::JobQueue::enter(long, bool) at /cppu/source/threadpool/jobqueue.cxx:115 16 in cppu_threadpool::ORequestThread::run() at /cppu/source/threadpool/thread.cxx:171 The problem is that the early-return case is (accidentally) doing the right thing for an attempt to join a thread that has already terminated normally, but the assertion must not trigger when the terminated thread's ID is re-used by a later thread. Change-Id: I2a6764d2ec189d96ccb366db14395029bb8e73ad
Diffstat (limited to 'sal/osl')
-rw-r--r--sal/osl/unx/thread.cxx12
1 files changed, 7 insertions, 5 deletions
diff --git a/sal/osl/unx/thread.cxx b/sal/osl/unx/thread.cxx
index 0b0316697d5c..c4cf0dbd88d8 100644
--- a/sal/osl/unx/thread.cxx
+++ b/sal/osl/unx/thread.cxx
@@ -427,8 +427,6 @@ sal_Bool SAL_CALL osl_isThreadRunning(const oslThread Thread)
void SAL_CALL osl_joinWithThread(oslThread Thread)
{
- pthread_t thread;
- bool attached;
Thread_Impl* pImpl= static_cast<Thread_Impl*>(Thread);
if (!pImpl)
@@ -436,7 +434,13 @@ void SAL_CALL osl_joinWithThread(oslThread Thread)
pthread_mutex_lock (&(pImpl->m_Lock));
- if (pthread_equal (pthread_self(), pImpl->m_hThread))
+ pthread_t const thread = pImpl->m_hThread;
+ bool const attached = ((pImpl->m_Flags & THREADIMPL_FLAGS_ATTACHED) > 0);
+
+ // check this only if *this* thread is still attached - if it's not,
+ // then it could have terminated and another newly created thread could
+ // have recycled the same id as m_hThread!
+ if (attached && pthread_equal(pthread_self(), pImpl->m_hThread))
{
assert(false); // Win32 implementation would deadlock here!
/* self join */
@@ -444,8 +448,6 @@ void SAL_CALL osl_joinWithThread(oslThread Thread)
return; /* EDEADLK */
}
- thread = pImpl->m_hThread;
- attached = ((pImpl->m_Flags & THREADIMPL_FLAGS_ATTACHED) > 0);
pImpl->m_Flags &= ~THREADIMPL_FLAGS_ATTACHED;
pthread_mutex_unlock (&(pImpl->m_Lock));