From b01740268c9cba59c93741e8028afafe67a2d170 Mon Sep 17 00:00:00 2001 From: Andrii Grynenko <andrii@fb.com> Date: Fri, 12 Feb 2016 10:22:25 -0800 Subject: [PATCH] Fix Singleton/ThreadLocal destruction order crashes in buck dev builds 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/folly/Singleton.cpp b/folly/Singleton.cpp index 66321bfd..1cf9c4d9 100644 --- a/folly/Singleton.cpp +++ b/folly/Singleton.cpp @@ -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() { -- 2.34.1