Fix Singleton/ThreadLocal destruction order crashes in buck dev builds
authorAndrii Grynenko <andrii@fb.com>
Fri, 12 Feb 2016 18:22:25 +0000 (10:22 -0800)
committerfacebook-github-bot-0 <folly-bot@fb.com>
Fri, 12 Feb 2016 19:20:29 +0000 (11:20 -0800)
Summary: This adds a folly::Singleton->folly::ThreadLocal dependency to make sure folly::ThreadLocal is always loaded first. Otherwise PthreadKeyUnregister singleton is created after folly::Singleton storage, even though it has higher priority.

Reviewed By: andrewjcg

Differential Revision: D2931170

fb-gh-sync-id: 36392d76e98201f2b4416b4bbef451d6c0e8c69d
shipit-source-id: 36392d76e98201f2b4416b4bbef451d6c0e8c69d

folly/Singleton.cpp

index 66321bfdc1e47c4e9a37285b405d8b0bb39cef51..1cf9c4d9efa673da6935a1f490a8002312188436 100644 (file)
@@ -213,6 +213,10 @@ void SingletonVault::reenableInstances() {
 }
 
 void SingletonVault::scheduleDestroyInstances() {
+  // Add a dependency on folly::ThreadLocal to make sure all its static
+  // singletons are initalized first.
+  threadlocal_detail::StaticMeta<void>::instance();
+
   class SingletonVaultDestructor {
    public:
     ~SingletonVaultDestructor() {