Menu

#33 FAQ answer for: Is log4cpp thread-safe?

open
nobody
None
5
2013-12-06
2013-12-05
No

The FAQ has the question "Is log4cpp thread-safe?" Currently, there is no answer provided. I'm interested to know the answer for that FAQ.

Discussion

  • Alexander Perepelkin

    Hello Craig,

    FAQ actually misses that point. Let me answer it here and if this answer looks exhaustive then I will add it to FAQ.

    The same instance of the log4cpp::Category object (a logger) can be used from different threads simultaneously without explicit synchronization. Concurrent access to the appenders will be prevented by the logger object itself. It will lock internal mutex each time when it comes to writing into appenders. So, it is safe, for example, to write from the multiple threads to the same logger which appends to the same file.
    Although, if you configure log4cpp in such a way that two different loggers append to the same appender (file), then there will be no way for the framework to arrange proper addition and things can get mixed up. So this way of configuration is not recommended.

     
  • Craig McQueen

    Craig McQueen - 2013-12-06

    That's really informative, thanks.

    Additional related question: The documentation also describes configure options --with-omnithreads and --with-pthreads. But it isn't clear what "enable multi-threading support" means, and whether log4cpp is/isn't thread safe with/without these options.

     
  • Alexander Perepelkin

    --with-omnithreads and --with-pthreads look to be some ancient stuff.
    Currently, these options are not recognized by configure script on modern systems like Ubuntu 12.04.
    I guess --with-pthreads option was supposed to turn on -pthread option for gcc compiler which in turn would tell a compiler to build and link with multithreaded runtime libraries. As of now -pthreads is added to gcc flags with or without this option (on Ubuntu).
    Although, that may not be true for the older/not-linux systems, where --with-pthreads flag still may be valuable.
    "Enable multi-threading support" means that compiler should link the code against multithreaded runtime libraries.

     

    Last edit: Alexander Perepelkin 2013-12-06

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.