title: Independent logging in multithreaded applications
body: <p>I'm currently debugging a multithreaded application (pthread under Linux ia64, ARM).
  valgrind, helgrind, and gdb are my currently used tools.</p>
  
  <p>There are some synchronizing issues and for later analysis,
  I want to log thread execution to one or more files.</p>
  
  <p>Naive implementation would do some write/fprintf which might
  (depending on the libc implementation) lock some internal mutex.
  That would in turn influence the program's behaviour
  (I would call it 'locking by accident')
  and is therefore not acceptable.</p>
  
  <p>Searching the internet yields only to the inverse solution,
  i.e. how to synchronize threads resp. how to log.
  NB: Third-party logging libraries tend to garuantee multithread-safety
  but not the opposite as described above.</p>
  
  <p>So I came up with unsynchronized caching the log entries in memory,
  on a per-thread basis, and flushing that to a file on program exit.</p>
  
  <p>I guess that this is a general problem for many developers and
  I wonder whether there is a <strong>better</strong> approach.
  Any suggestions?</p>