Kaydet (Commit) 8dc2f2f1 authored tarafından Michael Stahl's avatar Michael Stahl

sal: fix assert in osl_joinWithThread()

e3a74864 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
üst b02f792f
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment