From 4c2859303166eb4f17a084dc01cc218d6be703e4 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 19 Jul 2019 19:25:27 +0200 Subject: [PATCH] Fix races in rpmalloc initialization. Ensure rpmalloc_thread_initialize() int worker threads is called only after rpmalloc_initialize() was called on the main profiler thread. --- client/TracyProfiler.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 657b1102..95f73b92 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1179,6 +1179,8 @@ void Profiler::Worker() s_profilerTid = syscall( SYS_gettid ); #endif + while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); + rpmalloc_thread_initialize(); const auto procname = GetProcessName(); @@ -1187,8 +1189,6 @@ void Profiler::Worker() const auto hostinfo = GetHostInfo(); const auto hisz = std::min( strlen( hostinfo ), WelcomeMessageHostInfoSize - 1 ); - while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); - #ifdef TRACY_ON_DEMAND uint8_t onDemand = 1; #else @@ -1517,6 +1517,7 @@ void Profiler::Worker() void Profiler::CompressWorker() { + while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); rpmalloc_thread_initialize(); for(;;) {