Skip to content

Instantly share code, notes, and snippets.

@tylorr
Created November 21, 2015 20:36
Show Gist options
  • Save tylorr/9ac73d7a887d4053ee08 to your computer and use it in GitHub Desktop.
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
#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