diff --git a/common/kiid.cpp b/common/kiid.cpp index 07c21b2d24..16806551bd 100644 --- a/common/kiid.cpp +++ b/common/kiid.cpp @@ -33,8 +33,12 @@ #include #endif +#include + #include +// boost:mt19937 is not thread-safe +static std::mutex rng_mutex; // Create only once, as seeding is *very* expensive static boost::mt19937 rng; @@ -69,9 +73,14 @@ KIID::KIID() #endif if( createNilUuids ) + { m_uuid = nilGenerator(); + } else + { + std::lock_guard lock( rng_mutex ); m_uuid = randomGenerator(); + } #if BOOST_VERSION >= 106700 }