From 8cadbd6a474a03f032f3d181eb95bb72eb6809d8 Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Thu, 13 Aug 2026 09:46:16 +0000 Subject: [PATCH] [UR] fix data race on logger teardown flag --- unified-runtime/source/common/logger/ur_logger_details.hpp | 2 +- unified-runtime/source/common/logger/ur_sinks.hpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/unified-runtime/source/common/logger/ur_logger_details.hpp b/unified-runtime/source/common/logger/ur_logger_details.hpp index c9bf4715c5407..7f2ed808e48b9 100644 --- a/unified-runtime/source/common/logger/ur_logger_details.hpp +++ b/unified-runtime/source/common/logger/ur_logger_details.hpp @@ -55,7 +55,7 @@ class Logger { Args &&...args) { // During process/library teardown this logger's owned sinks may already // have been destroyed. Use a temporary stack sink instead. - if (isTearDowned) { + if (isTearDowned.load(std::memory_order_acquire)) { if (!isLegacySink && level < this->standardSinkLevel) { return; } diff --git a/unified-runtime/source/common/logger/ur_sinks.hpp b/unified-runtime/source/common/logger/ur_sinks.hpp index 30a5e4a9aa74e..a8c470cbd00b3 100644 --- a/unified-runtime/source/common/logger/ur_sinks.hpp +++ b/unified-runtime/source/common/logger/ur_sinks.hpp @@ -6,6 +6,7 @@ #ifndef UR_SINKS_HPP #define UR_SINKS_HPP 1 +#include #include #include #include @@ -19,7 +20,7 @@ namespace logger { -inline bool isTearDowned = false; +inline std::atomic isTearDowned = false; class Sink { public: @@ -48,7 +49,7 @@ class Sink { // the UR adapter. // TODO: Change adapters to use a common sink class in the loader instead of // using thier own sink class that inherit from logger::Sink. - if (isTearDowned) { + if (isTearDowned.load(std::memory_order_acquire)) { std::cerr << message; } else { print(level, message); @@ -186,7 +187,7 @@ class StderrSink : public Sink { this->flush_level = flush_lvl; } - ~StderrSink() { logger::isTearDowned = true; } + ~StderrSink() { logger::isTearDowned.store(true, std::memory_order_release); } }; class FileSink : public Sink {