Guard all uses of basic_random_generator for thread safety
This commit is contained in:
@@ -81,6 +81,8 @@
|
||||
#include <Base/Reader.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Writer.h>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
#include <Mod/Part/App/Geometry.h>
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
@@ -1393,9 +1395,13 @@ void Vertex::Restore(Base::XMLReader &reader)
|
||||
void Vertex::createNewTag()
|
||||
{
|
||||
// Initialize a random number generator, to avoid Valgrind false positives.
|
||||
// The random number generator is not threadsafe so we guard it. See
|
||||
// https://www.boost.org/doc/libs/1_62_0/libs/uuid/uuid.html#Design%20notes
|
||||
static boost::mt19937 ran;
|
||||
static bool seeded = false;
|
||||
static boost::mutex random_number_mutex;
|
||||
|
||||
boost::lock_guard<boost::mutex> guard(random_number_mutex);
|
||||
if (!seeded) {
|
||||
ran.seed(static_cast<unsigned int>(std::time(nullptr)));
|
||||
seeded = true;
|
||||
|
||||
Reference in New Issue
Block a user