From 572747a3f92186ce7f5f08c38aaa89382d3f20d9 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 21 Nov 2021 13:30:36 -0500 Subject: [PATCH] Protect KIID generator from threading --- common/kiid.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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 }