diff --git a/common/kiid.cpp b/common/kiid.cpp index 3ae572afbc..bd6c62211d 100644 --- a/common/kiid.cpp +++ b/common/kiid.cpp @@ -42,15 +42,13 @@ #include -// boost:mt19937 is not thread-safe -static std::mutex rng_mutex; - +// Use thread_local because boost:mt19937 is not thread-safe // Static rng and generators are used because the overhead of constant seeding is expensive // We rely on the default non-arg constructor of basic_random_generator to provide a random seed. // We use a separate rng object for cases where we want to control the basic_random_generator // initial seed by calling SeedGenerator from unit tests and other special cases. -static boost::mt19937 rng; -static boost::uuids::basic_random_generator randomGenerator; +static thread_local boost::mt19937 rng; +static thread_local boost::uuids::basic_random_generator randomGenerator; // These don't have the same performance penalty, but we might as well be consistent static boost::uuids::string_generator stringGenerator; @@ -87,7 +85,6 @@ KIID::KIID() } else { - std::lock_guard lock( rng_mutex ); m_uuid = randomGenerator(); }