Fix SingletonRelaxedCounter in T::~T() of ThreadLocal<T>
Summary: [Folly] Fix `SingletonRelaxedCounter` in `T::~T()` of `ThreadLocal<T>`. Given a type `T` which has a dtor which increments some `SingletonRelaxedCounter`, and given some use of a `ThreadLocal<T>` where, within some given thread, the only time `SingletonRelaexCounter` is incremented is in the `T` dtor, there would be a leak of the `LocalLifetime` and this leak would cause subsequent `SingletonRelaxedCounter::count()` to segfault with access to a deallocated local counter. C++ `thread_local` destructors run before `pthread` thread-specific destructors. If a `pthread` thread-specific destructor triggers initialization of a C++ `thread_local`, then that `thread_local` will be leaked in that its destructor will never be run. Fix this with `ThreadLocal` by detecting when `ThreadLocal` per-thread destructors have begun running. This is a larger issue with `pthread` thread-specific objects overall, but as long as we stick to using `ThreadLocal`, it can be papered over. Reviewed By: davidtgoldblatt Differential Revision: D13970469 fbshipit-source-id: a4c7f36d2c0d63f8f0e363ddb9d35a44b027aea6
Showing
Please register or sign in to comment