Patch didn't work, didn't spend much time trying to debug but was suprised to
see xmlsocketappender in the traceback given that I only have a
ConsoleAppender configured.  Commenting out the synchronization constructor
did take care of the issue though.  Below is the trace from the failed
patch:

GNU gdb Red Hat Linux (6.6-15.fc7rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu"...
Using host libthread_db library "/lib64/libthread_db.so.1".
(gdb) r
Starting program: /tmp/a.out 
[Thread debugging using libthread_db enabled]
[New Thread 46912518677056 (LWP 5674)]
2007-10-10 07:38:17,225 DEBUG test - testing
terminate called after throwing an instance of
'log4cxx::helpers::MutexException'
  what():  Mutex exception: stat = 22

Program received signal SIGABRT, Aborted.
[Switching to Thread 46912518677056 (LWP 5674)]
0x0000003ebf2305c5 in raise () from /lib64/libc.so.6
(gdb) where
#0  0x0000003ebf2305c5 in raise () from /lib64/libc.so.6
#1  0x0000003ebf232070 in abort () from /lib64/libc.so.6
#2  0x0000003ecd8bebd4 in __gnu_cxx::__verbose_terminate_handler () from
/usr/lib64/libstdc++.so.6
#3  0x0000003ecd8bcd96 in __gxx_personality_v0 () from
/usr/lib64/libstdc++.so.6
#4  0x0000003ecd8bcdc3 in std::terminate () from /usr/lib64/libstdc++.so.6
#5  0x0000003ecd8bceaa in __cxa_throw () from /usr/lib64/libstdc++.so.6
#6  0x00002aaaab117a7d in log4cxx::helpers::synchronized::synchronized () at
xmlsocketappender.cpp:94
#7  0x00002aaaab0e52ae in log4cxx::helpers::ObjectPtrBase::exchange
(destination=0x2aaaab38a060, newValue=0x0) at objectptr.cpp:51
#8  0x00002aaaab0cc832 in __tcf_6 () at
../../../src/main/include/log4cxx/helpers/objectptr.h:115
#9  0x0000003ebf233449 in exit () from /lib64/libc.so.6
#10 0x0000003ebf21dabb in __libc_start_main () from /lib64/libc.so.6
#11 0x0000000000401569 in _start ()


Curt Arnold-3 wrote:
> 
> Please try the following patch and see if it resolves your problem.   
> Reworking ObjectPtrBase::exchange for 64-bit builds was on my TO-DO  
> list, but I wanted to work through the rest of the backlog before  
> going to platform specific builds.  On 32-bit builds,  
> ObjectPtrBase::exchange calls apr_atomic_xchg32 which on most  
> processors will end up being a single machine instruction.  Until  
> recently APR did not have an equivalent call to exchange pointers (it  
> does now in the SVN, but hasn't appeared in a release yet), so there  
> were calls that used the Mutex abstraction from log4cxx.  What I  
> believe that you are running into is exchange() was first called in  
> the object destructor which means that it could occur after APR has  
> been terminated.  I've modified ObjectPtrBase so that the mutex is  
> accessed in the constructor which should guarantee that it is still  
> available in the matching destructor.   I have not tested the code  
> and it is not what I expect the final fix will be, but it may be  
> enough to get you going.
> 
> Ultimately, I'd expect to use apr_atomic_xchg32 on 32-bit builds,  
> InterlockedExchangePtr on Win64-builds, update configure to test for  
> the presence of apr_atomic_xchgptr and use that if available and only  
> then attempt to use the log4cxx Mutex abstraction.  log4cxx-0.9.7 did  
> not attempt to do any synchronization on object pointers.  If the fix  
> doesn't work for you, let the list know but you should be able to get  
> away with just commenting out the synchronization constructor.
> 
> 
> Index: src/main/cpp/objectptr.cpp
> ===================================================================
> --- src/main/cpp/objectptr.cpp        (revision 582963)
> +++ src/main/cpp/objectptr.cpp        (working copy)
> @@ -26,6 +26,17 @@
> 
>   using namespace log4cxx::helpers;
> 
> +ObjectPtrBase::ObjectPtrBase() {
> +#if APR_SIZEOF_VOIDP != 4
> +    getMutex();
> +#endif
> +}
> +
> +Mutex& ObjectPtrBase::getMutex() {
> +   static Mutex mutex(APRInitializer::getRootPool());
> +   return mutex;
> +}
> +
>   void ObjectPtrBase::checkNull(const int& null) {
>       if (null != 0) {
>          throw IllegalArgumentException("Attempt to set pointer to a  
> non-zero numeric value.");
> @@ -37,8 +48,7 @@
>      return (void*) apr_atomic_xchg32((volatile apr_uint32_t*)  
> destination,
>                             (apr_uint32_t) newValue);
>   #else
> -   static Mutex mutex(APRInitializer::getRootPool());
> -   synchronized sync(mutex);
> +   synchronized sync(getMutex());
>      void* oldValue = *destination;
>      *destination = newValue;
>      return oldValue;
> Index: src/main/include/log4cxx/helpers/objectptr.h
> ===================================================================
> --- src/main/include/log4cxx/helpers/objectptr.h      (revision 582963)
> +++ src/main/include/log4cxx/helpers/objectptr.h      (working copy)
> @@ -37,11 +37,16 @@
>   {
>       namespace helpers
>       {
> +        class Mutex;
> 
>           class LOG4CXX_EXPORT ObjectPtrBase {
>           public:
> +            ObjectPtrBase();
>               static void checkNull(const int& null);
>               static void* exchange(void** destination, void* newValue);
> +
> +        private:
> +            static Mutex& getMutex();
>           };
> 
> 
> 
> 
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/apps-throwing-MutexException-at-termination-tf4590301.html#a13134974
Sent from the Log4cxx - Users mailing list archive at Nabble.com.

Reply via email to