Skip to content

Commit 59dfcdf

Browse files
[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 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: NikolajBjorner <[email protected]>
1 parent bd56607 commit 59dfcdf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/util/warning.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Revision History:
2424
#include "util/buffer.h"
2525
#include "util/vector.h"
2626

27+
#ifndef SINGLE_THREAD
28+
#include <mutex>
29+
#endif
30+
2731
#ifdef _WINDOWS
2832
#if defined( __MINGW32__ ) && ( defined( __GNUG__ ) || defined( __clang__ ) )
2933
#include <crtdbg.h>
@@ -67,6 +71,10 @@ static bool g_use_std_stdout = false;
6771
static std::ostream* g_error_stream = nullptr;
6872
static std::ostream* g_warning_stream = nullptr;
6973

74+
#ifndef SINGLE_THREAD
75+
static std::mutex g_warning_mutex;
76+
#endif
77+
7078
void send_warnings_to_stdout(bool flag) {
7179
g_use_std_stdout = flag;
7280
}
@@ -129,6 +137,9 @@ void print_msg(std::ostream * out, const char* prefix, const char* msg, va_list
129137

130138
void warning_msg(const char * msg, ...) {
131139
if (g_warning_msgs) {
140+
#ifndef SINGLE_THREAD
141+
std::lock_guard<std::mutex> lock(g_warning_mutex);
142+
#endif
132143
va_list args;
133144
va_start(args, msg);
134145
print_msg(g_warning_stream, "WARNING: ", msg, args);

0 commit comments

Comments
 (0)