From fea25712ca54c4715f874cf3d871e84bbfd83352 Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Fri, 2 Mar 2012 12:24:38 -0700 Subject: [PATCH] Serialize access to debug.log stream Acquire an exclusive, advisory lock before sending output to debug.log and release it when we're done. This should avoid output from multiple threads being interspersed in the log file. We can't use CRITICAL_SECTION machinery for this because the debug log is written during startup and shutdown when that machinery is not available. (Thanks to Gavin for pointing out the CRITICAL_SECTION problems based on his earlier work in this area) --- src/util.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util.cpp b/src/util.cpp index b0c80f6dfc..d143306aec 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -25,6 +25,7 @@ namespace boost { #include #include #include +#include #include #include #include @@ -209,6 +210,8 @@ inline int OutputDebugStringF(const char* pszFormat, ...) if (fileout) { static bool fStartedNewLine = true; + static boost::mutex mutexDebugLog; + boost::mutex::scoped_lock scoped_lock(mutexDebugLog); // Debug print useful for profiling if (fLogTimestamps && fStartedNewLine)