Remove global init of ThreadLocal in Random
authorSubodh Iyengar <subodh@fb.com>
Wed, 15 Oct 2014 23:51:46 +0000 (16:51 -0700)
committerdcsommer <dcsommer@fb.com>
Fri, 17 Oct 2014 18:44:13 +0000 (11:44 -0700)
Summary:
Remove global initialization of ThreadLocal in Random
See https://gcc.gnu.org/onlinedocs/gcc-4.8.3/gcc/Thread-Local.html

Static initializers and thread locals don't mix well, and we're seeing
some crashes which we think might be related to this.

Test Plan: Unit tests

Reviewed By: seanc@fb.com

Subscribers: trunkagent, seanc, njormrod

FB internal diff: D1617455

folly/Random.cpp

index 06b3d5aea0b20a7f60e4f52d8b3b407119357957..f18d6f33a78f26bcc405c28b32c5d24f652e04dc 100644 (file)
@@ -90,11 +90,11 @@ void BufferedRandomDevice::getSlow(unsigned char* data, size_t size) {
   ptr_ += size;
 }
 
-ThreadLocal<BufferedRandomDevice> bufferedRandomDevice;
 
 }  // namespace
 
 void Random::secureRandom(void* data, size_t size) {
+  static ThreadLocal<BufferedRandomDevice> bufferedRandomDevice;
   bufferedRandomDevice->get(data, size);
 }