sal/osl/unx/thread.cxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
New commits: commit 8dc2f2f182e72e9fce277d8f5e9bcf3ce474f84f Author: Michael Stahl <mst...@redhat.com> Date: Thu Aug 6 18:09:49 2015 +0200 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 diff --git a/sal/osl/unx/thread.cxx b/sal/osl/unx/thread.cxx index 0b03166..c4cf0db 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)); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits