From 9ef34addb8c20112a504b848b126528014277049 Mon Sep 17 00:00:00 2001 From: bjovke Date: Tue, 27 Jun 2017 20:29:08 +0200 Subject: [PATCH] Problem: When using print_backtrace() on Linux with libunwind, printout of stack traces from multiple threads are interleaved. Solution: added static mutex to serialize printing of stack traces. --- src/err.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/err.cpp b/src/err.cpp index 76ebd51343..afadd7ef70 100644 --- a/src/err.cpp +++ b/src/err.cpp @@ -389,9 +389,12 @@ int zmq::wsa_error_to_errno (int errcode) #include #include #include +#include "mutex.hpp" void zmq::print_backtrace (void) { + static zmq::mutex_t mtx; + mtx.lock (); Dl_info dl_info; unw_cursor_t cursor; unw_context_t ctx; @@ -429,8 +432,10 @@ void zmq::print_backtrace (void) rc ? func_name : demangled_name, (unsigned long) offset); free (demangled_name); } - + puts (""); + fflush (stdout); + mtx.unlock (); } #else