Signal.cpp's activeThreads() should only create its ThreadGroup once.
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jul 2018 07:04:11 +0000 (07:04 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jul 2018 07:04:11 +0000 (07:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187634
<rdar://problem/40662311>

Reviewed by Yusuke Suzuki.

registerThreadForMachExceptionHandling() is relying on the activeThreads()
ThreadGroup being a singleton.

* wtf/threads/Signals.cpp:
(WTF::activeThreads):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233795 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/threads/Signals.cpp

index 52a0ccd..d4d791e 100644 (file)
@@ -1,3 +1,17 @@
+2018-07-13  Mark Lam  <mark.lam@apple.com>
+
+        Signal.cpp's activeThreads() should only create its ThreadGroup once.
+        https://bugs.webkit.org/show_bug.cgi?id=187634
+        <rdar://problem/40662311>
+
+        Reviewed by Yusuke Suzuki.
+
+        registerThreadForMachExceptionHandling() is relying on the activeThreads()
+        ThreadGroup being a singleton.
+
+        * wtf/threads/Signals.cpp:
+        (WTF::activeThreads):
+
 2018-07-12  David Kilzer  <ddkilzer@apple.com>
 
         Revert: iOS port should define HAVE_RUNLOOP_TIMER
index 229545a..59a550d 100644 (file)
@@ -209,10 +209,15 @@ inline void setExceptionPorts(const AbstractLocker& threadGroupLocker, Thread& t
     }
 }
 
-inline ThreadGroup& activeThreads()
+static ThreadGroup& activeThreads()
 {
-    static NeverDestroyed<std::shared_ptr<ThreadGroup>> activeThreads { ThreadGroup::create() };
-    return *activeThreads.get();
+    static std::once_flag initializeKey;
+    static ThreadGroup* activeThreadsPtr = nullptr;
+    std::call_once(initializeKey, [&] {
+        static NeverDestroyed<std::shared_ptr<ThreadGroup>> activeThreads { ThreadGroup::create() };
+        activeThreadsPtr = activeThreads.get().get();
+    });
+    return *activeThreadsPtr;
 }
 
 void registerThreadForMachExceptionHandling(Thread& thread)