title: How to buffer stdout in memory and write it from a dedicated thread
body: <p>I have a C application with many worker threads.  It is essential that these do not block so where the worker threads need to write to a file on disk, I have them write to a circular buffer in memory, and then have a dedicated thread for writing that buffer to disk.</p>
  
  <p>The worker threads do not block any more.  The dedicated thread can safely block while writing to disk without affecting the worker threads (it does not hold a lock while writing to disk).  My memory buffer is tuned to be sufficiently large that the writer thread can keep up.</p>
  
  <p>This all works great.  My question is, how do I implement something similar for stdout?</p>
  
  <p>I could macro printf() to write into a memory buffer, but I don't have control over all the code that might write to stdout (some of it is in third-party libraries).</p>
  
  <p>Thoughts?
  NickB</p>