[Wine] Log entries from different threads are mixed with each other

Martin Gregorie martin at gregorie.org
Sun Nov 21 16:11:05 CST 2010


On Sun, 2010-11-21 at 15:49 -0600, DieselMachine wrote:
> Can you please give more detailed explanation how it works and why it
> couldn't be fixed? I don't believe that there is no way to synchronize
> log entry writes. :) 
> 
If you've got more than one thread writing to the same file there's
nothing to stop their output being interleaved. 

There are three ways to prevent that:

- associate a mutex (lock) with the file and change all writing threads
  so that they can only write if they have the mutex. If they haven't,
  they'll have to wait until they get it.

- use a queue. Writers put logging output on the queue and a single
  log writer thread pulls messages off the queue and writes them to the
  log file. The queue will still need a mutex to stop writers from
  stamping all over the queue but, since the queue is in-memory, the
  waits, when they occur, will be very short. 

- give each thread its own log file, though that will make debugging
  harder because you'll have to correlate several files and you'll need
  to timestamp every log message to do that.  

Martin





More information about the wine-users mailing list