Commit eb493d16 authored by Robin Cheng's avatar Robin Cheng Committed by Facebook GitHub Bot

Fix race condition in //folly/test:synchronized_test due to sharing RNG on multiple threads.

Summary: Turned it into a thread_local instead. Only affects tests.

Reviewed By: yfeldblum

Differential Revision: D22744469

fbshipit-source-id: cbe8263d560f5abad27c7e61b1963aecf090a94e
parent ca49b1fe
......@@ -32,15 +32,10 @@
namespace folly {
namespace sync_tests {
inline std::mt19937& getRNG() {
static const auto seed = folly::randomNumberSeed();
static std::mt19937 rng(seed);
return rng;
}
void randomSleep(std::chrono::milliseconds min, std::chrono::milliseconds max) {
std::uniform_int_distribution<> range(min.count(), max.count());
std::chrono::milliseconds duration(range(getRNG()));
folly::ThreadLocalPRNG prng;
std::chrono::milliseconds duration(range(prng));
/* sleep override */
std::this_thread::sleep_for(duration);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment