protect RNG with mutex
#include "random_level_generator.h"
#include <random>
+#include <mutex>
namespace search::tensor {
@@ -16,16 +17,19 @@ namespace search::tensor {
class InvLogLevelGenerator : public RandomLevelGenerator {
std::mt19937_64 _rng;
+ std::mutex _mutex;
std::uniform_real_distribution<double> _uniform;
double _levelMultiplier;
public:
InvLogLevelGenerator(uint32_t m)
: _rng(0x1234deadbeef5678uLL),
+ _mutex(),
_uniform(0.0, 1.0),
_levelMultiplier(1.0 / log(1.0 * m))
{}
uint32_t max_level() override {
+ std::lock_guard<std::mutex> guard(_mutex);
double unif = _uniform(_rng);
double r = -log(1.0-unif) * _levelMultiplier;
return (uint32_t) r;
