From ce8ef4f19ea1212adde4d87103fc4dfaebf703a0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Oct 2025 20:34:13 +0000 Subject: [PATCH] Add mutex to warning.cpp for thread safety Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> --- src/util/warning.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/util/warning.cpp b/src/util/warning.cpp index 033c93780..c7becf49f 100644 --- a/src/util/warning.cpp +++ b/src/util/warning.cpp @@ -24,6 +24,10 @@ Revision History: #include "util/buffer.h" #include "util/vector.h" +#ifndef SINGLE_THREAD +#include +#endif + #ifdef _WINDOWS #if defined( __MINGW32__ ) && ( defined( __GNUG__ ) || defined( __clang__ ) ) #include @@ -67,6 +71,10 @@ static bool g_use_std_stdout = false; static std::ostream* g_error_stream = nullptr; static std::ostream* g_warning_stream = nullptr; +#ifndef SINGLE_THREAD +static std::mutex g_warning_mutex; +#endif + void send_warnings_to_stdout(bool flag) { g_use_std_stdout = flag; } @@ -129,6 +137,9 @@ void print_msg(std::ostream * out, const char* prefix, const char* msg, va_list void warning_msg(const char * msg, ...) { if (g_warning_msgs) { +#ifndef SINGLE_THREAD + std::lock_guard lock(g_warning_mutex); +#endif va_list args; va_start(args, msg); print_msg(g_warning_stream, "WARNING: ", msg, args);