3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-10-08 17:01:55 +00:00

[WIP] Add a mutex to warning.cpp to ensure that warning messages from different threads don't interfere (#7963)

* Initial plan

* Add mutex to warning.cpp for thread safety

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
Copilot 2025-10-06 13:38:18 -07:00 committed by GitHub
parent 3ce8aca411
commit cd1ceb6efe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -24,6 +24,10 @@ Revision History:
#include "util/buffer.h"
#include "util/vector.h"
#ifndef SINGLE_THREAD
#include <mutex>
#endif
#ifdef _WINDOWS
#if defined( __MINGW32__ ) && ( defined( __GNUG__ ) || defined( __clang__ ) )
#include <crtdbg.h>
@ -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<std::mutex> lock(g_warning_mutex);
#endif
va_list args;
va_start(args, msg);
print_msg(g_warning_stream, "WARNING: ", msg, args);