From ef6737d0cd3c61d80ed04c1c2b2704d9c5f4123b Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Tue, 2 Aug 2011 00:05:14 +0200 Subject: [PATCH] Shorten the time between freeing the lock and setting mStatus to STOPPED. --- indra/llcommon/llthread.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index 42367dc3c..b0cc64e59 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -99,11 +99,21 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap // Run the user supplied function threadp->run(); - llinfos << "LLThread::staticRun() Exiting: " << threadp->mName << llendl; + // Setting mStatus to STOPPED is done non-thread-safe, so it's + // possible that the thread is deleted by another thread at + // the moment it happens... therefore make a copy here. + char const* name = threadp->mName; // We're done with the run function, this thread is done executing now. threadp->mStatus = STOPPED; + // Only now print this info [doing that before setting mStatus + // to STOPPED makes it much more likely that another thread runs + // after the LLCurl::Multi::run() function exits and we actually + // change this variable (which really SHOULD have been inside + // the critical area of the mSignal lock)]. + llinfos << "LLThread::staticRun() Exiting: " << name << llendl; + return NULL; }