title: A line-based thread-safe std::cerr for C++
body: <p>What is the easiest way to create my own <code>std::cerr</code> so that it is line-by-line thread-safe.</p>
  
  <p>I am preferably looking for the code to do it.</p>
  
  <p>What I need is so that <code>a line of output</code> (terminated with <code>std::endl</code>) generated by one thread stays <code>as a line of output</code> when I actually see it on my console (and is not mixed with some other thread's output).</p>
  
  <hr>
  
  <p><strong>Solution</strong>: <code>std::cerr</code> is <em>much</em> slower than cstdio. I prefer using <code>fprintf(stderr, "The message")</code> inside of a <code>CriticalSectionLocker</code> class whose constructor acquires a thread-safe lock and the destructor releases it.</p>