I thought functions are thread safe if they don't modify non-local data.
My assumption is correct according to this answer. But, recently I came across this code,
int intRand(const int & min, const int & max) {
static thread_local std::mt19937 generator;
std::uniform_int_distribution<int> distribution(min,max);
return distribution(generator);
}
The code left me puzzled. Why does it use thread_local
if functions are already thread safe?