diff --git a/sdk/src/common/random.cc b/sdk/src/common/random.cc index 77b88cfa2a..e1c4d818c9 100644 --- a/sdk/src/common/random.cc +++ b/sdk/src/common/random.cc @@ -7,6 +7,7 @@ #include #include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -20,13 +21,16 @@ namespace common // https://github.com/opentracing-contrib/nginx-opentracing/issues/52 namespace { +static std::once_flag once; class TlsRandomNumberGenerator { public: TlsRandomNumberGenerator() noexcept { Seed(); - platform::AtFork(nullptr, nullptr, OnFork); + std::call_once(once, [](){ + platform::AtFork(nullptr, nullptr, OnFork); + }); } static FastRandomNumberGenerator &engine() noexcept { return engine_; }