使用activemq-cpp库创建新线程期间的分段错误问题

时间:2016-04-02 12:35:09

标签: c++ valgrind activemq-cpp

我的环境是opensuse,gcc5,clion,active-mq 3.10.0。 我错过了什么?启动程序后我遇到了Segmentation故障。

    class MyTask : public CompositeTask{


    public:
        MyTask() { }

    public:
        virtual bool isPending() const override {
            cout<<"MyTask()::isPending\n";
            return true;
        }

        virtual bool iterate() override {
            cout<<"MyTask()::iterate\n";
            return false;
        }


    };


    class RR{
        CompositeTaskRunner compositeTaskRunner;
    public:
        RR(){


              CompositeTask* m = new MyTask();
                compositeTaskRunner.addTask(m);
            }
            void start(){
                compositeTaskRunner.start();

            }


        };

main(){

      RR* runner = new RR();
      runner->start();

}
来自valgrind的输出

==12202== Memcheck, a memory error detector
==12202== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==12202== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==12202== Command: ./CppMicroServicesExampleDriver
==12202== Parent PID: 9602
==12202== 
==12202== Invalid read of size 8
==12202==    at 0x5BDCD29: createThreadInstance (Threading.cpp:365)
==12202==    by 0x5BDCD29: decaf::internal::util::concurrent::Threading::createNewThread(decaf::lang::Thread*, char const*, long long) (Threading.cpp:920)
==12202==    by 0x5C21BB3: decaf::lang::Thread::initializeSelf(decaf::lang::Runnable*, std::string const&, long long) (Thread.cpp:123)
==12202==    by 0x5C21F7A: decaf::lang::Thread::Thread(decaf::lang::Runnable*, std::string const&) (Thread.cpp:102)
==12202==    by 0x5A5AC36: activemq::threads::CompositeTaskRunner::CompositeTaskRunner() (CompositeTaskRunner.cpp:70)
==12202==    by 0x40F5E1: RR::RR() (nano.hpp:32)
==12202==    by 0x40BEAD: main (main.cpp:56)
==12202==  Address 0x60 is not stack'd, malloc'd or (recently) free'd
==12202== 
==12202== 
==12202== Process terminating with default action of signal 11 (SIGSEGV)
==12202==  Access not within mapped region at address 0x60
==12202==    at 0x5BDCD29: createThreadInstance (Threading.cpp:365)
==12202==    by 0x5BDCD29: decaf::internal::util::concurrent::Threading::createNewThread(decaf::lang::Thread*, char const*, long long) (Threading.cpp:920)
==12202==    by 0x5C21BB3: decaf::lang::Thread::initializeSelf(decaf::lang::Runnable*, std::string const&, long long) (Thread.cpp:123)
==12202==    by 0x5C21F7A: decaf::lang::Thread::Thread(decaf::lang::Runnable*, std::string const&) (Thread.cpp:102)
==12202==    by 0x5A5AC36: activemq::threads::CompositeTaskRunner::CompositeTaskRunner() (CompositeTaskRunner.cpp:70)
==12202==    by 0x40F5E1: RR::RR() (nano.hpp:32)
==12202==    by 0x40BEAD: main (main.cpp:56)
==12202==  If you believe this happened as a result of a stack
==12202==  overflow in your program's main thread (unlikely but
==12202==  possible), you can try to increase the size of the
==12202==  main thread stack using the --main-stacksize= flag.
==12202==  The main thread stack size used in this run was 8388608.
==12202== 
==12202== HEAP SUMMARY:
==12202==     in use at exit: 126,122 bytes in 577 blocks
==12202==   total heap usage: 1,031 allocs, 454 frees, 152,249 bytes allocated
==12202== 
==12202== LEAK SUMMARY:
==12202==    definitely lost: 0 bytes in 0 blocks
==12202==    indirectly lost: 0 bytes in 0 blocks
==12202==      possibly lost: 0 bytes in 0 blocks
==12202==    still reachable: 126,122 bytes in 577 blocks
==12202==                       of which reachable via heuristic:
==12202==                         stdstring          : 15,204 bytes in 453 blocks
==12202==         suppressed: 0 bytes in 0 blocks
==12202== Rerun with --leak-check=full to see details of leaked memory
==12202== 
==12202== For counts of detected and suppressed errors, rerun with: -v
==12202== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

1 个答案:

答案 0 :(得分:0)

在使用库之前,必须调用其初始化方法,以准备管理资源所需的所有内部构造。

    activemq::library::ActiveMQCPP::initializeLibrary();
相关问题