Bug 1412298 - Wait for cooperative threads before worker threads when shutting down the JS shell, r=jandem.
authorBrian Hackett <bhackett1024@gmail.com>
Wed, 01 Nov 2017 09:53:51 -0600
changeset 389579 33134954c638c1516caa20d6d13b0dce378af389
parent 389578 0d54ccb489cb5083a6e20c83343482538332bd45
child 389580 9cff4b8eb3965ec0aa67be915f36e087bfb32538
push id96884
push userbhackett@mozilla.com
push dateWed, 01 Nov 2017 15:54:00 +0000
treeherdermozilla-inbound@33134954c638 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1412298
milestone58.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 1412298 - Wait for cooperative threads before worker threads when shutting down the JS shell, r=jandem.
js/src/jit-test/tests/basic/bug1412298.js
js/src/shell/js.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/bug1412298.js
@@ -0,0 +1,6 @@
+if (helperThreadCount() === 0)
+  quit();
+evalInCooperativeThread(`
+      const dbg = new Debugger();
+      evalInWorker("");
+`);
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -3920,16 +3920,23 @@ ScheduleWatchdog(JSContext* cx, double t
     return true;
 }
 
 static void
 KillWorkerThreads(JSContext* cx)
 {
     MOZ_ASSERT_IF(!CanUseExtraThreads(), workerThreads.empty());
 
+    // Yield until all other cooperative threads in the main runtime finish.
+    while (cooperationState->numThreads) {
+        CooperativeBeginWait(cx);
+        CooperativeYield();
+        CooperativeEndWait(cx);
+    }
+
     if (!workerThreadsLock) {
         MOZ_ASSERT(workerThreads.empty());
         return;
     }
 
     while (true) {
         // We need to leave the AutoLockWorkerThreads scope before we call
         // js::Thread::join, to avoid deadlocks when AutoLockWorkerThreads is
@@ -3942,23 +3949,16 @@ KillWorkerThreads(JSContext* cx)
             thread = workerThreads.popCopy();
         }
         thread->join();
     }
 
     js_delete(workerThreadsLock);
     workerThreadsLock = nullptr;
 
-    // Yield until all other cooperative threads in the main runtime finish.
-    while (cooperationState->numThreads) {
-        CooperativeBeginWait(cx);
-        CooperativeYield();
-        CooperativeEndWait(cx);
-    }
-
     js_delete(cooperationState);
     cooperationState = nullptr;
 }
 
 static void
 CancelExecution(JSContext* cx)
 {
     ShellContext* sc = GetShellContext(cx);