Fix races in TLRefCount
authorAndrii Grynenko <andrii@fb.com>
Thu, 28 Apr 2016 04:00:57 +0000 (21:00 -0700)
committerFacebook Github Bot 9 <facebook-github-bot-9-bot@fb.com>
Thu, 28 Apr 2016 04:05:31 +0000 (21:05 -0700)
commitbccbb1025da4f0efcb9c922b7cc6f01b07e49e18
treec558baef2b3297218eedbaced1bf3e70bfb1f669
parent68cf03b1e6ecad45fa51496cfd9e6ae34e5c1f34
Fix races in TLRefCount

Summary:
This fixes 2 races in TLRefCount:
1. Thread-local constructor race, exposed by the stress test. It was possible for LocalRefCount to be created (grabbing collectGuard), but not be added to the thread-local list, so that accessAllThreads wasn't collecting it. collectAll() was then blocking waiting on baton to be posted, causing a dead-lock.
2. LocalRefCount::count_ has to be made atomic, because otherwise += operation may be not flushed (nbronson explained the race in D3133443).

Reviewed By: djwatson

Differential Revision: D3166956

fb-gh-sync-id: 17d58a215ebfc572f8316ed46bafaa5e6a9e2368
fbshipit-source-id: 17d58a215ebfc572f8316ed46bafaa5e6a9e2368
folly/experimental/TLRefCount.h
folly/experimental/test/RefCountTest.cpp