From: Michael Hendricks Date: Fri, 2 Mar 2012 19:24:38 +0000 (-0700) Subject: Serialize access to debug.log stream X-Git-Tag: v0.4.0-unstable~129^2~1^2^2^2^2~4 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=a0ea95d3ceacea5868b8f921c36bbdddb5dc2b1b 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) --- diff --git a/src/util.cpp b/src/util.cpp index 6dc2f3b..ccd39aa 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -22,6 +22,7 @@ namespace boost { #include #include #include +#include using namespace std; using namespace boost; @@ -193,6 +194,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)