Guten Tag chihhsiw,
am Montag, 21. Mai 2018 um 11:37 schrieben Sie:

>   Thanks for reading this post. I have a C program running on CentOS 5.11,
> compiled through g++ calling a C++ library and this C++ library try to use
> log4cxx to do logging.

You didn't tell which version of log4cxx you are using, it might be
worth it to test with a current master.

> However, when I initialize
> LoggerPtr Log4XXLogger::loggerMyMain(Logger::getLogger( "main")); as global
> variable, my program hang at startup and gdb stack is like

How did you configure log4cxx before that call? Like with your class
example at the bottom, you first need to configure and that retrieve a
logger.

> #0  0xffffe405 in __kernel_vsyscall ()
> #1  0x0067bcc5 in pthread_cond_wait@@GLIBC_2.3.2 () from
> /lib/libpthread.so.0
> #2  0x0096b9cc in __cxa_guard_acquire () from /usr/lib/libstdc++.so.6
> #3  0xf764fa0e in log4cxx::helpers::Transcoder::decode (src="70023",
> dst="Mutex exception: stat = ") at transcoder.cpp:247

This looks like two problems: First log4cxx is throwing some
MutexException because it can't create a necessary mutex instance
using APR. That shouldn't happen and is either related to how you use
log4cxx, e.g. you didn't configure it it properly, or there might be
something broken regarding APR, log4cxx and whatever. So I suggest to
first look into why that exception gets thrown using some debugger, so
that you don't rely on the string error message being created, but are
able to see the return value of apr_thread_mutex_create. Have a look
at the CTORs of "mutex.cpp", one of them is used and throwing the
exception.

The second problem seems to be that the CXA guard doesn't seem to be
released ever for some reason. That shouldn't happen as well and might
mean that you have some problems regarding multi-threading, some
deadlock or such. That as well heavily depends on how you actually
configure log4cxx and such.

https://stackoverflow.com/questions/26013650/threadsafe-lazy-initialization-static-vs-stdcall-once-vs-double-checked-locki

> but if I make it as part of class, start the global variable as NULL and
> then new and assign as class A below
[...]
> my log message is unpredictable, sometimes produce 0 line sometimes produces
> many lines.

Maybe I'm missing something, but the configuration itself looks OK to
me. Where and how do you create instances of class A? Your problem
could again be related to multiple threads creating multiple instances
of class A, configuring log4cxx multiple time.

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail: thorsten.schoen...@am-soft.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow

Reply via email to