+// After GC is complete, we must wait for all GC threads to enter the
+// standby state, otherwise they may still be executing inside
+// any_work(), and may even remain awake until the next GC starts.
+static void
+shutdown_gc_threads (nat n_threads USED_IF_THREADS)
+{
+#if defined(THREADED_RTS)
+ nat i;
+ rtsBool wakeup;
+ for (i=1; i < n_threads; i++) {
+ do {
+ ACQUIRE_LOCK(&gc_threads[i]->wake_mutex);
+ wakeup = gc_threads[i]->wakeup;
+ // wakeup is false while the thread is waiting
+ RELEASE_LOCK(&gc_threads[i]->wake_mutex);
+ } while (wakeup);
+ }
+#endif
+}
+