logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Moul, Russell G" <russell.g.m...@boeing.com>
Subject Loggers and threading
Date Fri, 24 Jun 2005 22:53:07 GMT
I'm encountering problems using multiple threads that log to the same
logger.  The following is a simple test I put together to issolate the
problem and a backtrace from the failure.  Any suggestions would be
welcome.

Russ


#include "RawStressTest.hh"
#include <cc++/thread.h>
#include <log4cxx/logger.h>
#include <sstream>

namespace test {

using namespace log4cxx;
using namespace std;

/*
 * A thread to exercise logging, just log a bunch of messages.
 */
class Worker : public ::ost::Thread {
    public:
    Worker(string name) {setName(name.c_str());};
    void run() {
        LoggerPtr logger = Logger::getLogger(string(getName(),0,8));
        int i = 0;
        while (i++ <= 10000) {
            std::ostringstream oss;
            oss << " - " << i;
            LOG4CXX_INFO(logger, oss.str());
        }
    }
};

/*
 * Creates the test threads, starts them and then joins them.
 */
void RawStressTest::testThreads() {
    const int len = 100;
    Worker* threadLst[len]; 
    for (int i = 0; i < len; i++) {
        std::ostringstream oss;
        oss << "Worker_" << i;

        threadLst[i] = new Worker(oss.str());
        threadLst[i]->start();
    }
  
    for (int i = 0; i < len; i++) {
        threadLst[i]->join();
    }
}

} // end test namespace

int main(int argc, char* argv[]) {
    test::RawStressTest test = test::RawStressTest();
    test.testThreads();
}



(gdb) bt
#0  0x403bbe01 in kill () from /lib/i686/libc.so.6
#1  0x4034b1ed in pthread_kill () from /lib/i686/libpthread.so.0
#2  0x4034b58b in raise () from /lib/i686/libpthread.so.0
#3  0x403bbba4 in raise () from /lib/i686/libc.so.6
#4  0x403bd05d in abort () from /lib/i686/libc.so.6
#5  0x402ef527 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.5
#6  0x402ef574 in std::terminate () from /usr/lib/libstdc++.so.5
#7  0x402ef6e6 in __cxa_throw () from /usr/lib/libstdc++.so.5
#8  0x402a8eab in std::__throw_length_error () from
/usr/lib/libstdc++.so.5
#9  0x402dface in std::string::reserve () from /usr/lib/libstdc++.so.5
#10 0x402dff82 in std::string::append () from /usr/lib/libstdc++.so.5
#11 0x400ff6e5 in log4cxx::helpers::APRCharsetDecoder::decode
(this=0x8056d28, in=@0x44202c04, out=@0x44202c84) at
/home/rgm9335/pc_share/CVS-VOB/logging-log4cxx/src/charsetdecoder.cpp:85
#12 0x400deeec in log4cxx::helpers::Transcoder::decode (src=0x809b7cc "
- 130", len=6, dst=@0x44202c84) at
/home/rgm9335/pc_share/CVS-VOB/logging-log4cxx/src/transcoder.cpp:65
#13 0x400dfb11 in decode<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > (src=@0x44202dd4, dst=@0x44202c84) at
transcoder.h:48
#14 0x4017f363 in log4cxx::Logger::forcedLog (this=0x806fe18,
level=@0x804ac70, message=@0x44202dd4, location=@0x44202dc4) at
/home/rgm9335/pc_share/CVS-VOB/logging-log4cxx/src/logger.cpp:106
#15 0x080495ac in test::Worker::run (this=0x80b0c80) at
cpp/RawStressTest.cpp:42
#16 0x402237be in ost::ThreadImpl::ThreadExecHandler (th=0x80b0c80) at
thread.cpp:1110
#17 0x402229bf in ccxx_exec_handler (th=0x80b0c80) at thread.cpp:1136
#18 0x40348e21 in pthread_start_thread () from /lib/i686/libpthread.so.0
#19 0x4047108a in clone () from /lib/i686/libc.so.6
(gdb)

Russ Moul
MMA Mission Software
(253) 657-3036


Mime
View raw message