Bug 1573160 - shutdown newly-spawned threads if we're shutting down; r=mccr8
authorNathan Froyd <froydnj@mozilla.com>
Thu, 15 Aug 2019 17:29:26 +0000
changeset 488325 486c1d9d10912074867ea4b255107007224bedf7
parent 488324 4678b2d85df43ab5869f50df5ce616ef484ebcd6
child 488326 fa80b89e0ce4969bed9ffe465c726b99878d94ae
push id113906
push userncsoregi@mozilla.com
push dateFri, 16 Aug 2019 04:07:24 +0000
treeherdermozilla-inbound@d887276421d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1573160
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1573160 - shutdown newly-spawned threads if we're shutting down; r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D41551
xpcom/threads/nsThreadPool.cpp
--- a/xpcom/threads/nsThreadPool.cpp
+++ b/xpcom/threads/nsThreadPool.cpp
@@ -112,17 +112,19 @@ nsresult nsThreadPool::PutEvent(already_
                                   getter_AddRefs(thread), nullptr, stackSize);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return NS_ERROR_UNEXPECTED;
   }
 
   bool killThread = false;
   {
     MutexAutoLock lock(mMutex);
-    if (mThreads.Count() < (int32_t)mThreadLimit) {
+    if (mShutdown) {
+      killThread = true;
+    } else if (mThreads.Count() < (int32_t)mThreadLimit) {
       mThreads.AppendObject(thread);
     } else {
       killThread = true;  // okay, we don't need this thread anymore
     }
   }
   LOG(("THRD-P(%p) put [%p kill=%d]\n", this, thread.get(), killThread));
   if (killThread) {
     // We never dispatched any events to the thread, so we can shut it down