Created
November 21, 2015 20:36
-
-
Save tylorr/9ac73d7a887d4053ee08 to your computer and use it in GitHub Desktop.
Combination of thread_local, inline, and std::t19937 causes thead_number to sporadically become 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <random> | |
inline auto &prng_engine() { | |
thread_local std::random_device rd{}; | |
thread_local std::mt19937 engine{rd()}; | |
return engine; | |
} | |
int main() { | |
thread_local int32_t thead_number = 1; | |
while (thead_number > 0) { | |
std::uniform_int_distribution<int> dist{0, 1}; | |
dist(prng_engine()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment