I'm currently debugging a multithreaded application (pthread under Linux ia64, ARM). valgrind, helgrind, and gdb are my currently used tools.
There are some synchronizing issues and for later analysis, I want to log thread execution to one or more files.
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.
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.
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.
I guess that this is a general problem for many developers and I wonder whether there is a better approach. Any suggestions?
Modern multi-thread safe high performance loggers normally:
snprintf or any other formatting happens in the thread that emits a log message. E.g. a log message is a copy of the format string and the arguments (the format string can be shallow-copied).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With