Protect KIID generator from threading

This commit is contained in:
Jon Evans 2021-11-21 13:30:36 -05:00
parent 016a98df86
commit 572747a3f9
1 changed files with 9 additions and 0 deletions

View File

@ -33,8 +33,12 @@
#include <boost/uuid/entropy_error.hpp>
#endif
#include <mutex>
#include <wx/log.h>
// 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<std::mutex> lock( rng_mutex );
m_uuid = randomGenerator();
}
#if BOOST_VERSION >= 106700
}