From 09e43c53168c62b276b6c214949796be5516aa8f Mon Sep 17 00:00:00 2001 From: Oliver Clark Rickard Date: Wed, 11 Apr 2018 19:51:42 -0700 Subject: [PATCH] Leak the global static mutex in CKTextKitContext to avoid static destructor fiasco I haven't tested this code, but this is what I would try to resolve https://github.com/facebook/componentkit/issues/892. Someone should run some smoke tests with something like the above --- ComponentTextKit/TextKit/CKTextKitContext.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ComponentTextKit/TextKit/CKTextKitContext.mm b/ComponentTextKit/TextKit/CKTextKitContext.mm index ccf334a00..56d7b3b81 100644 --- a/ComponentTextKit/TextKit/CKTextKitContext.mm +++ b/ComponentTextKit/TextKit/CKTextKitContext.mm @@ -30,8 +30,8 @@ - (instancetype)initWithAttributedString:(NSAttributedString *)attributedString { if (self = [super init]) { // Concurrently initialising TextKit components crashes (rdar://18448377) so we use a global lock. - static std::mutex __static_mutex; - std::lock_guard l(__static_mutex); + static std::mutex *__static_mutex = new std::mutex; + std::lock_guard l(*__static_mutex); // Create the TextKit component stack with our default configuration. _textStorage = (attributedString ? [[NSTextStorage alloc] initWithAttributedString:attributedString] : [[NSTextStorage alloc] init]); _layoutManager = layoutManagerFactory ? layoutManagerFactory() : [[NSLayoutManager alloc] init];