Hello,
i annotated some bug reports earlier when i realized
they may have the same pattern... so i decided to make
it a bug report itself.
Well the cause is just an old problem of dependant
global objects: construction order.
// snip begin+++ appender.cpp
namespace log4cpp {
Appender::AppenderMap* Appender::_allAppenders;
threading::Mutex Appender::_appenderMapMutex; <---
-
this mutex object poses the problem!!!
// snip end---
The order of initialization is undefined across compilation
units. So if someone uses (like me) static log instance
references at global files scope they must be initialized
at the beginning.
example:
static log4cpp::Category& =
log4cpp::Category::getInstance
() .... constructs a new Appender, which gets added to
map
of appenders.
If the mutex, which is used to protect the map is not yet
constructed (in another compilation unit) -> *boom*.
Solutions: not elegant ones yet ...
1.) instead of "threading::Mutex
Appender::_appenderMapMutex;"
use "first time access - first init"
threading::Mutex& _getAppenderMapMutex()
{
static threading::Mutex mutex;
return mutex;
}
2.) #pragma init_seg (non portable)
Note: some other compilation units use the same
technique for construction of global MT guards ...
possibly same problem.
Regards,
Anastasius Focht