From 4f1dd8760ad4442d24cc7e67092a9ac50a36ccd0 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 23 Mar 2017 22:42:48 +0300 Subject: Fix diagnostics interleaving characters --- butl/diagnostics | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'butl/diagnostics') diff --git a/butl/diagnostics b/butl/diagnostics index 56219ce..0c22337 100644 --- a/butl/diagnostics +++ b/butl/diagnostics @@ -21,10 +21,23 @@ namespace butl // // Diagnostics destination stream (std::cerr by default). Note that its - // modification is not MT-safe. + // modification is not MT-safe. Also note that concurrent writing to the + // stream from multiple threads can result in interleaved characters. To + // prevent this an object of diag_lock type (see below) must be created prior + // to write operation. // LIBBUTL_EXPORT extern std::ostream* diag_stream; + // Acquire the diagnostics exclusive access mutex in ctor, release in dtor. + // An object of the type must be created prior to writing to diag_stream (see + // above). + // + struct LIBBUTL_EXPORT diag_lock + { + diag_lock (); + ~diag_lock (); + }; + struct diag_record; template struct diag_prologue; template struct diag_mark; -- cgit v1.1