Hi, I'm using Torjo's logging library in both an exe and a dll loaded from that exe (OS: Windows Xp, Compiler VC71 - /MD compile flag - multithreaded dll). I need the exe and the dll to have independent logs, as the dll are plugins implemented by third parties which may or not use boost log. The approach I was trying to follow was: - The exe declares/defines the log it needs. In its main function it initializes the logging system (appenders/modifiers/flush_log_cache). - Some of the dlls (at least the ones developed by me), declare/defines their own logs. In the DllMain they initialize theri logging system (appenders/modifiers/flush_log_cache). Is this expected to work? I made some tests and I got an access violation when exiting the main app, in the destructor of default_log_manager_impl(). (I can send a simple test case if needed). I also tried to compile the exe with BOOST_LOG_DYN_LINK but I always get the access violation (don't know if this could help - I remember to have seen this suggested in a similar case). What am i doing wrong? Paolo Coletta
Hi, Paolo Coletta wrote:
Is this expected to work? I made some tests and I got an access violation when exiting the main app, in the destructor of default_log_manager_impl(). (I can send a simple test case if needed).
With the current implementation this won't work. The problem is that the log instances do not unregister themselves from the log manager upon destruction. So when the Boost Logging DLL gets unloaded it will try to call a virtual destructor on all registered log instances, but the corresponding vtable pointers could already be invalid if the DLL that contains the logs has already been unloaded. I've already reported this problem to John. The fix for this is easy, you have to unregister logs when they are destroyed, i.e. in their destructor, from the log manager. Best Regards, Martin
Martin Ecker
Hi,
Paolo Coletta wrote:
Is this expected to work? I made some tests and I got an access violation when exiting the main app, in the destructor of default_log_manager_impl(). (I can send a simple test case if needed).
With the current implementation this won't work. The problem is that the log instances do not unregister themselves from the log manager upon destruction. So when the Boost Logging DLL gets unloaded it will try to call a virtual destructor on all registered log instances, but the corresponding vtable pointers could already be invalid if the DLL that contains the logs has already been unloaded.
I've already reported this problem to John. The fix for this is easy, you have to unregister logs when they are destroyed, i.e. in their destructor, from the log manager.
Could putting the initialization stuff in a class constructor, and instantiating an object of that class before anything else in your main, be of any help? (if there are any statics created, this will ensure they get created first, and therefore, destroyed last). I had similar problems, and after doing this, the crashes stopped. No guarantee of course since they were intermittent to start with, and I don't know if DLL's are unloaded after all statics destroyed or before or if it's even specified. Anyone know? Oliver
Oliver wrote:
Could putting the initialization stuff in a class constructor, and instantiating an object of that class before anything else in your main, be of any help?
That's actually what happens. As I wrote in my previous mail, the obvious solution is to deregister log objects (which are static objects) from the log manager in the Boost.Logging DLL when the DLL is unloaded (i.e. in the destructor of the static log object).
with, and I don't know if DLL's are unloaded after all statics destroyed or before or if it's even specified. Anyone know?
Under Windows with MSVC, static objects of a module are destroyed when the module is unloaded. So for static objects in DLLs this happens in DllMain (or more precisely in the DllMain wrapper of the C runtime that calls the user-supplied DllMain) in response to DLL_PROCESS_DETACH. Best Regards, Martin
participants (3)
-
Martin Ecker
-
Oliver
-
Paolo Coletta