Fix bug in circular singleton creation detection
authorChip Turner <chip@fb.com>
Wed, 3 Sep 2014 19:22:45 +0000 (12:22 -0700)
committerSara Golemon <sgolemon@fb.com>
Tue, 9 Sep 2014 21:22:23 +0000 (14:22 -0700)
commitbe42394a1a5aae9689a7a02b7d9e9333829f37e6
tree68116956490406067b16775e1343fc7d5ef55fc0
parent2bfde4cdaf98e1d638bc92e6e705a7590cd67386
Fix bug in circular singleton creation detection

Summary:
We considered it circular if we tried to create a singleton
while the singleton was being created.  In a single threaded world, this
is correct, but under concurrency, two threads can be in the singleton
creation codepath and become confused about the state of the singleton.

This change uses a condition variable to notify when creation completes
so that other threads can wait on the creation to complete.  Circular
creation is detected via thread id.

Test Plan:
runtests (new test case; failed without the fix, passes with
it)

Reviewed By: hans@fb.com

Subscribers: lins, anca, njormrod, rkroll

FB internal diff: D1534081
folly/experimental/Singleton.cpp
folly/experimental/Singleton.h
folly/experimental/test/SingletonTest.cpp