fix race between StaticMetaBase::destroy() and StaticMetaBase::onThreadExit()
authorPhilip Pronin <philipp@fb.com>
Wed, 2 Nov 2016 04:24:55 +0000 (21:24 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Wed, 2 Nov 2016 04:38:42 +0000 (21:38 -0700)
commit206dce5b9e700e02026fbff304433d066c90ab3c
tree39fbb1deca89abbeb7a1ea9773b2871a06c90353
parent5e1b7327af577c40fb60cb1cdd08f9b413e2f2d6
fix race between StaticMetaBase::destroy() and StaticMetaBase::onThreadExit()

Summary:
We would like to guarantee that after `folly::ThreadLocal<>` dtor
returns no per-thread instances are longer alive.  Currently this is not a case:

* T1 is excuting `StaticMetaBase::onThreadExit()`, it acquired all per-thread
  instances and erased them from meta under `accessAllThreadsLock_`.
* T2 destroys `folly::ThreadLocal<>`, it executes `StaticMetaBase::destroy()`,
  collects all per-thread instances (thus missing the ones being destroyed by
  T1), destroys them and returns.
* T1 executes dtor of per-thread instances, after parent `folly::ThreadLocal<>`
  dtor is finished.

Reviewed By: ot

Differential Revision: D4109820

fbshipit-source-id: d547b8cc77c9871126538c38644c2e98ddccf220
folly/ThreadCachedInt.h
folly/detail/ThreadLocalDetail.cpp